0

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> ";
?>
2

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

echo ' <a href="http://www.bing.com/search?q=' . urlencode($titletest) . '">' . $titletest . '</a>';
|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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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