Self-referencing canonical
-
Hey, I have a problem with adding self-referencing canonical on a blog subpage. I tried different options. Plugins like Yoast, Rank Math, do not work, i.e. the option with canonical is active but canonical links are not added to the page code. I have tested various options and the only one that fairly works is to add the following code in the header.php:
<?php if ( is_front_page() ) { $canonical_url = get_home_url(); if ( ! is_main_site() ) { // add trailing slash for subsite home directories $canonical_url = $canonical_url . '/'; } } else { $canonical_url = get_permalink(); } ?> <link rel="canonical" href="<?php echo $canonical_url ?>" />
The problem with this solution is that the blog subpage or categories from the blog as canonical have… the only article that has been published on the blog.
I have run out of ideas and I don’t know what to do about it. I would prefer to avoid installing any more plugins.
I would appreciate any help or guidance on what I can do to make it work.
The page I need help with: [log in to see the link]
- The topic ‘Self-referencing canonical’ is closed to new replies.