Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I want to make a custom query that checks the post title and puts in a different URL like this:

<a href=bing.com/search?q=<?php echo single_post_title(); ?>>Blablabla</a>

But it does not work for me if I have a post with a space in it, like Hello World. Then it only shows me Hello in the link. How can I get the full post title?

I tried this too, but did not work, just like the first one.

<?php
$titletest = get_the_title();

echo " <a href=http://www.bing.com/search?q=$titletest>$titletest</a> ";
?>
share|improve this question
add comment

1 Answer 1

Damn, I came with a solution after I posted it....

echo ' <a href="http://www.bing.com/search?q=' . urlencode($titletest) . '">' . $titletest . '</a>';
share|improve this answer
1  
+1 for solving your own question. Yes, spaces are invalid characters in URLs. You have to encode them. –  s_ha_dum Jul 31 '13 at 16:12
    
Thanks man. This feels better than asking :) –  Johan Jul 31 '13 at 21:21
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.