WordPress can’t echo brackets

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}

Read More

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');
    while($query->have_posts()){
        $query->the_post();
        $url = the_permalink();
        $keyword = the_title();
        Print('<p>' . $url . '{' . $keyword . '}' . '</p><br>');
    }
    echo 'Done';

}

Related posts

Leave a Reply

1 comment

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

    while($query->have_posts()){
        $query->the_post();
        $url = get_permalink();
        $keyword = get_the_title();
        Print('<p>' . $url . '{' . $keyword . '}' . '</p><br>');
    }