At present all https pages have their own canonical tags referencing https, which is incorrect, they should be referencing the http versions.



has the following canonical tag:

<link rel='canonical' href='https://www.example.com' />

How can we make the canonical tags on https pages use the http URLs?

  • Note for others: this is bad idea, you should have only https URLs on your site and therefore the canonical URL should also be an HTTPS url. These URLs never get dereferenced by the client, so they won't trigger an security warning. But you don't want a search engine indexing an HTTP version of your page because if a user clicks on it from the search engine they will be vulnerable. Commented Sep 5, 2019 at 17:11

3 Answers 3


You can change it using following code, add it in your theme function.php or in plugin.

remove_action ( 'wp_head' , 'rel_canonical' ) ;
add_action ( 'wp_head' , 'my_rel_canonical' ) ;

function my_rel_canonical () {
    ob_start () ;
    rel_canonical () ;
    $rel_content = ob_get_contents () ;
    ob_end_clean () ;
    echo str_replace ( "https:" , "http:" , $rel_content ) ;

Do you plan to use the canonical to avoid duplicate content in Google? I believe it's a wrong approach. You should eliminate the duplicate content by 301-redirecting pages to the proper scheme, either SSL or non-SSL, depending on the content (checkout, login, admin). And not using the canonical.

Edit: did I just repeat what you said earlier? https://webmasters.stackexchange.com/a/49852


The way https is implemented is correct. If you force http upon https, your clients will see a warning stating the site has unsecure content. Yet if you want to do it, there are 2 ways:

  1. Using Apache's mod_rewrite to rewrite all HTTPS URLS to HTTP as mentioned here.
  2. Using a custom filter in wordpress to change all URLS on the fly.

    function custom_force_http( $force_http, $post_id = 0, $url = '' ) {
      return str_replace ( "https:" , "http:" , $force_http) ;
    add_filter('force_http' , 'custom_force_http', 10, 3);

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.