What is the best practice to show social icons always on all the posts and pages.

Already I am firing pre_get_comments in my functions.php to show a sidebar between the post content and the comments. Also I added the code after the_content() of page.php...

The Question: How can I choose the propper Hook?

  1. Fire pre_get_comments + add code after the_content() in page.php...
  2. Filter the_content() and use conditionals, something as is_singular()...

What is the best practice? Why?

  • 1
    If it helps, there are several cases in which pre_get_comments won't get fired: post types without comments support, specific templates not loading the comments' template, posts without comments if the comments are closed, etcetera. I would probably stick with the_content filter facing several conditionals first. – Luis Sanz Apr 4 '16 at 22:20
  • 1
    If you want to add social icons to post and pages, why use a hook for comments? Use the_content filter. – cybmeta Apr 5 '16 at 6:58
  • Good Point. Yes you both are right, comments are not always firing with content. I choice the_content filter adding some conditional before inside the custom_function. Thank you :) – Apeiron Apr 5 '16 at 9:46

As noted by @cybmeta the most convenient way to add something on every post would be to use the_content filter.

This may give you unexpected results on archive pages, because some themes use the_content to display information on those, while others use the_excerpt. So, depending on what you want, you may want to use the filter on the_content only on singular pages or add the same filter to the excerpt as well.`

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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