user3675015
user3675015

Reputation: 1

Echo php the_title within php variable?

How do I echo:

<?php the_title(); ?>

Within the variable below, after "q="

<?php
    $feedURL = 'https://gdata.youtube.com/feeds/api/videos?q=<?php the_title(); ?>&orderby=published&start-index=11&max-results=10&v=2';
?>

Upvotes: 0

Views: 902

Answers (4)

wicguam
wicguam

Reputation: 51

What you want to use here is get_the_title() function.

The function you are using (the_title()) it is used to print the value (although you can force it to just return the value, more info)

Your code would look like this:

<?php
    $feedURL = 'https://gdata.youtube.com/feeds/api/videos?q=' . get_the_title() . '&orderby=published&start-index=11&max-results=10&v=2';
?>

Upvotes: 2

Collin Green
Collin Green

Reputation: 2196

You're already in php, so you don't need to open php tags again. Simply concatenate the variable on the string.

<?php
    $feedURL = 'https://gdata.youtube.com/feeds/api/videos?q=' . the_title() . '&orderby=published&start-index=11&max-results=10&v=2';
?>

Edited to use . instead of + to match PHP.

Upvotes: -1

Padmanathan J
Padmanathan J

Reputation: 4620

Try this

<?php
$title = the_title(); 
    $feedURL = 'https://gdata.youtube.com/feeds/api/videos?q='.urlencode($title).'&orderby=published&start-index=11&max-results=10&v=2';
?>

Upvotes: 0

Navneil Naicker
Navneil Naicker

Reputation: 3691

Something like this

<?php
    $feedURL = 'https://gdata.youtube.com/feeds/api/videos?q=' . get_the_title() . '&orderby=published&start-index=11&max-results=10&v=2';
?>

Upvotes: 0

Related Questions