WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.

$titletest = get_the_title();

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

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 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

Your Answer


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.