I wrote a guest blog post for another website. I'd like to publish this same blog post on my website but include a canonical URL that points to the original publisher.
This allows me to post the article on my website while notifying Search Engines of the canonical location of the post and avoiding SEO penalties.
In the wp_head action, WordPress prints a
rel=canonical tag automatically and places it in the head for posts.
I tried to use a snippet of code to output my own
rel=canonical (possibly compounding the already automatically output one) with:
<?php if ( is_single('1234') ) echo '<link rel="canonical" href="https://www.examplesite.com/my-guest-post" />'; ?>
Upon inspection, this code never prints to the page. I imagine it might have to do with parse order.
Does anyone know how I might correctly implement this? I don't want to mess with the WordPress native code too much but would like to find a simple mechanism that lets me alter the
rel=canonical meta tag on a per post basis.
I do not want to use Yoast.
Thanks in advance,