- This topic has 8 replies, 4 voices, and was last updated 4 years, 3 months ago by Agus Sriyana.
January 3, 2018 at 12:23 pm #462562Satori
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:
I already installed the facebook’ SDK via the WP Head Hook.GeneratePress 2.0.1GP Premium 1.5.6January 3, 2018 at 3:00 pm #462659LeoStaffCustomer SupportJanuary 3, 2018 at 6:15 pm #462725Satori
This is the code provided by facebook:
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.January 3, 2018 at 11:20 pm #462813TomLead DeveloperLead 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.January 4, 2018 at 1:25 pm #463320Satori
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.January 4, 2018 at 11:09 pm #463536TomLead DeveloperLead Developer
Have you considered trying a plugin?:
https://en-ca.wordpress.org/plugins/facebook-comments-plugin/January 4, 2018 at 11:52 pm #463547Satori
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.January 5, 2018 at 9:54 am #463948TomLead DeveloperLead 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; ?>March 8, 2018 at 3:59 pm #515155Agus Sriyana
- You must be logged in to reply to this topic.