0

I'm using wordpress platform for my website. And I'm using custom-permalink plugin for url customization.Now,how can I get that customized url as canonical url without trailing slash issue? Sample links are mentioned below.

https://www.drona.in

https://www.drona.in/govt-jobs/karnataka/haveri-district-court-recruitment-notification

If you see canonical URL for given second URL above,the extra slash is added at the end.

Now I want whichever URL is present for a post,the same URL should come as canonical URL.

Thanks in Advance.

I have already tried with Yoast settings, permalinks settings. And I'm using Thesis theme.

Pavan Vanam
  • 15
  • 1
  • 8

1 Answers1

0

use this code for dynamic canonical URL.

<link rel="canonical" href="https://www.yourdomain.com<?php echo 
$_SERVER['REQUEST_URI'];?>">

Try this function

function wpse_302620_canonical_url( $canonical_url, $post ) {
if ( $post->ID === 1234 ) {
    $canonical_url = 'https://www.examplesite.com/my-guest-post';
} 

return $canonical_url;
}
add_filter( 'get_canonical_url', 'wpse_302620_canonical_url', 10, 2 );

Hope its working for you

Harsh Khare
  • 507
  • 1
  • 3
  • 13
  • I'm using Thesis theme,Its not like all the themes and doesnt have header.php,footer.php etc – Pavan Vanam Jan 22 '19 at 13:03
  • Try this function function wpse_302620_canonical_url( $canonical_url, $post ) { if ( $post->ID === 1234 ) { $canonical_url = 'https://www.examplesite.com/my-guest-post'; } return $canonical_url; } add_filter( 'get_canonical_url', 'wpse_302620_canonical_url', 10, 2 ); – Harsh Khare Jan 22 '19 at 13:07
  • Where should I add this wpse_302620_canonical_url()? – Pavan Vanam Jan 23 '19 at 09:26
  • In Function file – Harsh Khare Jan 23 '19 at 09:28
  • I'm using thesis theme...There is no functions.php file http://diythemes.com/thesis/ – Pavan Vanam Jan 23 '19 at 10:01
  • You have only admin section access? – Harsh Khare Jan 23 '19 at 10:32
  • I'm having FTP access too... Do you know thesis theme files structure? – Pavan Vanam Jan 23 '19 at 11:06
  • Now I can add a canonical tag from functions.php. But I want to remove previous existed(default) canonical tag. I tried with add_filter( 'wpseo_canonical', '__return_false' ); and also I tried with remove_action('wp_head', 'rel_canonical'); But not working. I'm using Yoast SEO plugin. – Pavan Vanam Jan 24 '19 at 05:44
  • Try this function remove_canonical() { add_filter( 'wpseo_canonical', '__return_false', 10, 1 ); } add_action('wp', 'remove_canonical'); can you vote up for my answer for other help – Harsh Khare Jan 24 '19 at 05:54
  • Yeah,I tried with this also. I saw it at https://stackoverflow.com/questions/10529409/removing-rel-canonical-added-by-yoast-seo-plugin – Pavan Vanam Jan 24 '19 at 06:13