2

There's an external website that I'll be referencing within my posts that uses the same static format for their pages. Let's say it's website.com/view/1111, website.com/view/1112, etc.

What I want to do is create a post template that will automatically append a link to that external site above the post content. So, for example, if my post was titled 1337, the post would automatically include a link at the top "View on website.com" that would point to website.com/view/1337.

Alternatively, if that's not feasible to include in a template file, it'd be fine if it were just a shortcode I could use at the beginning of posts.

I tried adding <?php echo “<a href='website.com/view/<?php the_title(); ?>’>View on website.com</a>” ; ?> in my template and that broke the site, so, guessing I did not do that properly.

1 Answer 1

2

OH I figured it out.

     <?php $myvariable = get_the_title( ''. '', false );
        echo "<a href='website.com/view/$myvariable'>View on website.com</a>";
        ?>

Hopefully this helps someone else!

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.