I'm trying to use WordPress template tags (through shortcodes) to merge the post title and url into hyperlink html code. Which looks like this:

<a href="[Permalink]">[Post Title]</a>.

Problem is the text output uses curly quotes around the "Permalink" that are not compatible with html code. I tried placing hyperlink code using template tags (shortcodes) into a code snippet box, however then the shortcodes won't run.

I would like to merge the template tags (through shortcodes) into the hyperlink html code first, then have it show up in a code snippet box. Any ideas on how to do that?


Just tested this and it worked on my end. The shortcode itself would be [titlelink]

function titlelink_ssc($content = null) {

        echo '<a href="'.get_permalink().'" title="'.get_the_title().'">'.get_the_title().'</a>';
        $titlelink_ssc = ob_get_clean();
        return $titlelink_ssc;

add_shortcode("titlelink", "titlelink_ssc");
  • Why do you do the ob_start() and echo instead of just returning the string?
    – Jan Fabry
    May 19 '11 at 18:32
  • Hmm...now that you ask, I'm not sure. I guess I've just always included the ob_start() in my shortcode functions. I believe it's mainly due to the fact that most of the shortcode functions I write involve adding a secondary loop.
    – Norcross
    May 20 '11 at 7:53

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.