This should be an easy thing but I just can’t get it right.

I need to add a piece of HTML to every page on my site however the weird theme I’m using doesn’t have a header or footer file that every page uses and I don’t want to duplicate code.

So what I did was add the following to my functions.php file

add_filter ('the_content', 'AddTrackingScript');

function AddTrackingScript($content) {
    $Tracker .= '<script type="text/javascript">....</script>';
    $content = $Disclaimer .= $content;
    return content;

This works on all articles and pages however the text isn’t being added to my home page or to the category pages. Is there a different filter I need to use other than the_content?

There is a lot more logic in my real function as certain posts in certain categories don’t get the added text but I’ve simplified it here, just in case someone spots a type 😉

Read more here: How can I add text to all posts/pages/categories/homepage etc


If you know the solution of this issue, please leave us a reply in Comment section, to update the question.

Wordpress related questions and answers: