Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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

e.g:

https://www.example.com

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?

share|improve this question

3 Answers 3

up vote 5 down vote accepted
+25

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 ) ;
}
share|improve this answer

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);
    
share|improve this answer
    
I've just found out this is incorrect, the browser won't see the canonical tag as an unsecure element. See here: webmasters.stackexchange.com/questions/67119/… –  moobot Jul 18 at 2:17

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? http://webmasters.stackexchange.com/a/49852

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.