Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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?

share|improve this question

1 Answer 1

up vote 0 down vote accepted

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

function titlelink_ssc($content = null) {

        ob_start();
        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");
share|improve this answer
    
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

 
discard

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

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