[Resolved] Facebook Comments On Single Posts

Home Forums Support [Resolved] Facebook Comments On Single Posts

Home Forums Support Facebook Comments On Single Posts

Viewing 9 posts - 1 through 9 (of 9 total)
  • Author
  • #462562

    Hi! I was using Facebook comments on my posts by using a hook. Anyway, I later discovered this wasn’t correct, as basically all the posts were sharing the same comments. So now I understand I have to install the comments in the single.php file, as this will create independent instances for every post.

    I have already installed a child theme (thanks Leo for providing link). And have created a copy of the single.php file and move it to the child theme folder. The thing is, it is unclear to me what portion of the code should I override to insert the code provided by facebook:

    <div class="fb-comments"></div>

    I already installed the facebook’ SDK via the WP Head Hook.

    GeneratePress 2.0.1
    GP Premium 1.5.6
    Customer Support

    Hi there,

    What’s the code you are trying to insert and where did they say to insert it?


    This is the code provided by facebook:

    <div class=”fb-comments”
    data-width=”500″ data-numposts=”5″>

    Basically they say I should insert it wherever I want the comments plugin to show in. I want to insert it in the single.php file. As I said, I’m using a child theme. It’s just unclear to me what part of the code in the single.php should I override.

    Lead Developer
    Lead Developer

    Inserting it via hook vs single.php should make zero difference.

    Have you added that code in the single.php to test? You should just have to add the HTML anywhere in the single.php file.


    Well, basically all of my posts are sharing the same comments. If I make a comment on post 1 it does appear on post 2. And inserting the html on the single.php doesn’t work. I have tried the hook again and it loads the module. Any suggestion on how to resolve this? It’s kinda bizarre.

    Should I make a copy of the comments.php to the child theme and then erase everything and paste the facebook’s html? As I understand that is the template for the comments section.

    Lead Developer
    Lead Developer

    Hi Tom. I just got it to work. The first code I was sharing had the wrong url. I mean, I was always using the main url of my site, that’s why all pages were sharing comments, because the comments got assigned to that url. So the trick here is to insert some php calling the actual permalink.

    So this is the first code:

    <div class="fb-comments" data-href="https://developers.facebook.com/docs/plugins/comments#configurator" data-numposts="5"></div>

    And here is how is supposed to be in order to just work:

    <div class="fb-comments" data-href="<?php the_permalink(); ?>" data-width="100%" data-numposts="5" data-mobile="Auto-detect" data-colorscheme="light" data-order-by="time"></div>

    The secret is “<?php the_permalink(); ?>”. But one thing I noticed is that the code can’t be inserted anywhere in the single.php file as you noted. It’s only on the after main content area where it works. If I try to put it below the comments_template it doesn’t load.

    Anyway, thank you for the suggestion on plugins. I’m trying to understand how to do certain things without using a plugin. I’m happy I understand this a little bit more.

    Lead Developer
    Lead Developer

    Ahh yes, that makes sense.

    You should be able to place it in the “After Content” hook in GP Hooks, inside a conditional:

    <?php if ( is_single() ) : ?>
        Your code in here
    <?php endif; ?>
    Agus Sriyana


Viewing 9 posts - 1 through 9 (of 9 total)
  • You must be logged in to reply to this topic.