WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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 am trying to make a simple plugin that will output the URL and title of a post. It should look like this:

http://mysite.com/test-2/{Test 2}

However when I use the code that I posted below, it prints as follows:

http://mysite.com/test-2/Test 2


I can't figure out why. I've tried to escape them, separating each bracket into a string and combining them, but nothing seems to work.

Heres the code

function P2S_menu(){
    echo '<h1>This is a Test</h1>';

    $query = new WP_Query($query_string . '&orderby=title&order=asc&posts_per_page=-1');
        $url = the_permalink();
        $keyword = the_title();
        Print('<p>' . $url . '&#123;' . $keyword . '&#125;' . '</p><br>');
    echo 'Done';

share|improve this question

migrated from stackoverflow.com Jul 24 '11 at 9:54

This question came from our site for professional and enthusiast programmers.

The functions the_permalink() and the_title() print their results by default. Use get_permalink() and get_the_title() instead:

    $url = get_permalink();
    $keyword = get_the_title();
    Print('<p>' . $url . '&#123;' . $keyword . '&#125;' . '</p><br>');
share|improve this answer
Thanks, worked perfectly! – user849170 Jul 23 '11 at 21:28
@user849170: Mark the answer as accepted to let others know that the issue is resolved. – You Jul 23 '11 at 21:43

Your Answer


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