Currently I'm working on a website, where there are posts and I intend to give the possibility the user to jump to the adjacent posts with a simple link pointing to them. It will be with get_next_post_link() and get_previous_post_link(). First I wanted put these in the content via the_content filter hook, but in another question of mine Mark Kaplun informed me that this is a bad idea because:

Just don't do it. The the_content filter supposed to automatically amend the content, while what you are trying to do is to add a decoration, not a content. You are going to hurt in very unexpected ways depending on where exactly you set the filter and how well you remove it after your intended use. (for example, place it in a global scope and your excerpts might get the links)

If you have to manipulate the content being displayed by adding a decoration to it, do it in the theme, no other place.

That what I try to do, but my question is: Exactly where I have to put this type of decoration not to cause any unwanted interaction?


When you develop a theme you can add specific styling per each post type. by default they all use the single.php theme file, but single-{post-type}.php will be used for the specific post type being displayed (for the full template hierarchy - https://developer.wordpress.org/themes/basics/template-hierarchy/#the-template-file-hierarchy)

The navigation links like the prev and next ones you are trying to add are usually added outside the loop which displays the content itself. I suggest to take a look at one of the core themes to see what is the canonical way to do it.

  • Thank you Mark for the answer, meanwhile I inserted in the single.php right after the content() call as it doesn't hurt the contents, but I will study the links and core themes as you proposed. – Geeocode Feb 23 '18 at 22:10

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.