最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

shortcode - Adding variable for post title so post template can include auto-generated link to view on external website.com{post

programmeradmin5浏览0评论

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/view/1111, website/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" that would point to website/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/view/<?php the_title(); ?>’>View on website</a>” ; ?> in my template and that broke the site, so, guessing I did not do that properly.

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/view/1111, website/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" that would point to website/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/view/<?php the_title(); ?>’>View on website</a>” ; ?> in my template and that broke the site, so, guessing I did not do that properly.

Share Improve this question edited Aug 6, 2020 at 16:24 Ianthe MB Dempsey asked Aug 6, 2020 at 16:16 Ianthe MB DempseyIanthe MB Dempsey 413 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 2

OH I figured it out.

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

Hopefully this helps someone else!

发布评论

评论列表(0)

  1. 暂无评论