Recovering Facebook comments for all links after moving to HTTPS

Home Forums General issues Recovering Facebook comments for all links after moving to HTTPS

This topic contains 24 replies, has 4 voices, and was last updated by  Mark Wolters 5 months ago.

Viewing 25 posts - 1 through 25 (of 25 total)
  • Author
    Posts
  • #26345 Reply

    Michael

    Hey Rogier,

    After moving my entire site to HTTPS (and using the RSSSL mixed content option), my Facebook comments disappeared. I have Facebook comments appear on multiple pages.

    I’m using this code right now:

    function rsssl_exclude_http_url($html) {
    //replace the https url back to http
    $html = str_replace(‘data-href=”https://www.domain.com”‘, ‘data-href=”http://www.domain.com”‘, $html); return $html;
    }
    add_filter(“rsssl_fixer_output”,”rsssl_exclude_http_url”);

    And it’s working specifically for https://www.domain.com to http://www.domain.com.

    But I also need to do that for https://www.domain.com/xxyyzz to http://www.domain.com/xxyyzz.

    How can I adjust the code above so I can make that happen?

    Thanks!

    Mike

    #26346 Reply

    If you remove the closing quotes, like this:

    function rsssl_exclude_http_url($html) {
    //replace the https url back to http
    $html = str_replace(‘data-href=”https://www.domain.com‘, ‘data-href=”http://www.domain.com‘, $html); return $html;
    }
    add_filter(“rsssl_fixer_output”,”rsssl_exclude_http_url”);

    It should work. When the quotes are gone, it will replace back any string with that domain. In the former version it would replace all strings ending with a quote.

    #26375 Reply

    Michael

    Thank you so much! That worked.

    #33898 Reply

    Nils

    Hi,

    Thank you for a great plug-in! I’m experiencing the same problem (disappearing FB comments) and I’m exited that I found this solution here but… Where do I place this code? I would love a detailed explanation if possible as I’m not so skilled with code 🙂

    Many thanks

    nils

    #53585 Reply

    Sunday Ukafia

    @Nils

    Add the code to your theme’s function.php file (You can add it at the end)

    Navigate to appearance – editor – functions.php (located at the right hand side)

    Note that the code will be removed if you update your theme.

    It is recommended to create a child theme and add it to your child theme function.php

    Google how to create a WordPress Child theme for help. Its actually quite simple.

    Goodluck

    -Sukafia

    #64635 Reply

    igorber
    Participant

    I’ve tried the solution posted above (added the code to the functions.php). but I am getting the following error: Parse error: syntax error, unexpected ‘function’ (T_FUNCTION) in /wp-content/themes/Fonovit/functions.php on line 1093. Any ideas why it does not work in my case? (https://vitafon.pl/bol-plecow.html)

    Thanks a lot for any advice!

    Igor

    #64657 Reply

    This might happen if there’s a PHP error on the line before. For example, if the last line before the function did not end with ;

    #64672 Reply

    igorber
    Participant

    Thank you for the reply. It have been the case, so I have added ; to the previous function(seems like it was missing there), but I still get an error Parse error: syntax error, unexpected ‘=’ in /wp-content/themes/Fonovit/functions.php on line 1095, if I place it in the front (just after <?php) of functions.php I also get: Parse error: syntax error, unexpected ‘=’ in /wp-content/themes/Fonovit/functions.php on line 5

    A bit lost here. No clue what is causing it.

    #64689 Reply

    What code is on line 5?

    #64696 Reply

    igorber
    Participant

    The same. I’ve tried to paste it to the beginning of the document and to the end (not at the same time), just to be sure it is not some strange character that got into functions.php accidentally. When I paste it to the document the website stops working. When I remove it all works fine

    #64697 Reply

    What I mean is, the error says there’s a fatal error on line 5. To say anything about it, I need to know what code you have on line 5.

    Possibly the quotes are changed by copying them. In that case you can try retyping the quotes in the code. If you post the line of code that is causing the error I might be able to help.

    #64705 Reply

    igorber
    Participant

    Seems like the quotes were the problem. At least the website is working fine.
    That the code I have now.

    function rsssl_exclude_http_url($html) {
    //replace the https url back to http
    $html = str_replace(‘data-href=”https://www.vitafon.pl’, ‘data-href=”http://www.vitafon.pl’, $html); return $html;
    }
    add_filter(“rsssl_fixer_output”,”rsssl_exclude_http_url”);

    But I still do not see the comments https://vitafon.pl/przepuklina-kregoslupa.html

    Could it be the way the facebook comments are implemented (as a code snippet inside of the theme)

    <div class=”facebook-comments”>
    <div class=”fb-comments” data-href=”<?php echo get_permalink( $post->ID ); ?>” data-width=”576″ data-numposts=”15″></div>
    </div>

    Thank you so much!

    #64717 Reply

    You can also try to change the og:url back to http:
    $html = str_replace(‘og:url=”https://’, ‘og:url=”http://’, $html);

    If that doesn’t help, you need to check how Facebook returns the shares. I have a very simple script to test this:
    https://really-simple-ssl.com/test-shares.php
    Where you can compare the shares that Facebook returns for the (recovered) share button, and the shares that are returned using the API. If you enter the http url, and the button does not show the correct number of shares, you can only recover the shares by using the API, and not using this replace script.

    You need to enter the url with http to see the correct results.

    #64800 Reply

    igorber
    Participant

    Thank you for your help. It seems that I need to use the API (still have to figure out how to do it :)) and the script does not work in my case. Thank you for your help!

    #64899 Reply

    In case you don’t want to do this yourself: the social add-on for Really Simple SSL has also built in share buttons, which use the API. You can customize the buttons using a template and css

    https://really-simple-ssl.com/downloads/really-simple-ssl-social/

    #64907 Reply

    igorber
    Participant

    Would that plugin recover comments that disappeared after moving to SSL? That is what I need the most.

    #64908 Reply

    No, I’m sorry, the API is used for shares only.

    #65408 Reply

    igorber
    Participant

    Tried different options (seemed quite straightforward) (also paid plugin http://www.heateor.com/facebook-comments-moderation/). Lost on what could be the problem. Do you provide premium support service or maybe you could recommend someone who could have a look at my website and see what the problem is?
    Regards,

    Igors

    #65554 Reply

    We’d have to investigate the plugin to see how it is retrieving the comments, and if there is a hook that can be used to override the URL. If you contact us https://really-simple-ssl.com/support and send us a zipped file of your comments plugin, we can take a look.

    #70516 Reply

    thietkethicongnhadep

    I also used the code as instructed above however when put in funtion.php the site does not work.
    function rsssl_exclude_http_url ($ html) {
    // thay thế địa chỉ https vào http
    $ html = str_replace (‘data-href = “https://thietkethicongnhadep.net/”,’ data-href = “http://thietkethicongnhadep.net/” ‘, $ html); return $ html;
    }
    add_filter (“rsssl_fixer_output”, “rsssl_exclude_http_url”);
    Anyway thank you very much

    #70683 Reply

    Mark Wolters
    Keymaster

    Hi, there shouldn’t be a space between the & and html. They should be written together, like this:

    function rsssl_exclude_http_url ($html) {
    // thay thế địa chỉ https vào http
    $html = str_replace ('data-href = "https://thietkethicongnhadep.net/",' data-href = "http://thietkethicongnhadep.net/" ', $html); return $html;
    }
    add_filter ("rsssl_fixer_output", "rsssl_exclude_http_url");

    that should make it work. Please also pay attention if the ” and ‘ qoutes are parsed correctly in your editor. That might cause it to fail as well.

    Mark

    #74511 Reply

    ephram

    This works only if Auto-replace mixed content are turned off, is it a way to make it work without turning it off (for the http part) ?

    global $post, $url ;
    $compare_date = strtotime( “2018-01-21″ );
    $post_date = strtotime( $post->post_date );

    $url = get_permalink();

    if ( $compare_date >= $post_date ) {

    //old post published with http
    $url = str_replace(‘https://’, ”, $url); ?>

    <div class=’fb-comments’ data-href=”http://<?php echo $url ?>” data-width=”715″ data-numposts=”5″></div> <?
    } else { ?>
    //new post published after https
    <div class=’fb-comments’ data-href=”<? echo get_permalink(); ?>” data-width=”715″ data-numposts=”5″></div>

    <?

    }

    #74650 Reply

    Mark Wolters
    Keymaster

    Hi Ephram,

    it sounds like the mixed content fixer is replacing the data-href to https:// as well. This is something that should be fixed by adding this code to your theme’s functions.php file (replacing yourdomain.com with your own domain):

    function rsssl_exclude_http_url ($html) {
    $html = str_replace ('data-href = "https://yourdomain.com/",' data-href = "http://yourdomain.com/" ', $html); return $html;
    }
    add_filter ("rsssl_fixer_output", "rsssl_exclude_http_url");

    Can you check if the code is present in your theme’s functions.php file?

    Mark

    #98376 Reply

    Ian

    Thanks for this invaluable bit of code.

    I’m having a problem with displaying comment counts post the SSL update though.

    Are there any solutions?

    Prior to moving to SSL, I could get comment counts from this: <fb:comments-count href=”<?php echo get_permalink($post->ID); ?>”></fb:comments-count>

    Sample page is here: https://www.doubleeyelidmusic.com/someone-say-t-shirt-sale/

    Any insight would be great, I’m a total novice here.

    #98426 Reply

    Mark Wolters
    Keymaster

    Hi Ian,

    since the site has moved to SSL the get_permalink function will likely return an https:// permalink. If the comments are made on http:// this can result in an incorrect count. However it does seem that the url used by the Facebook comments plugin is http://. I’d suggest to contact the developer of the comments plugin about this, perhaps they can provide you with more information about why this is happening.

    Mark

Viewing 25 posts - 1 through 25 (of 25 total)
Reply To: Recovering Facebook comments for all links after moving to HTTPS
Your information: