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

1 Answer 1

2

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

echo ' <a href="http://www.bing.com/search?q=' . urlencode($titletest) . '">' . $titletest . '</a>';
1
  • 1
    +1 for solving your own question. Yes, spaces are invalid characters in URLs. You have to encode them.
    – s_ha_dum
    Commented Jul 31, 2013 at 16:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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