Insert a different code in the head of home, category and post
-
Hello how are you? I need to insert a different analytics and ads code for each section, each note and my homepage. I have three different ad and analytics scripts, which I want to insert in the head of my homepage, another in the head of the article and another in the head of the category.
I’ve been reading and could do it using hooks (wp_head) in functions.php.
The homepage code, I insert it in header.php, so it would not require creating anything, it should for categories and posts.
This is my code (which I am putting at the end of functions.php), I still don’t know how to do it for posts. Loading it in the functions.php doesn’t give me any error, but it doesn’t work. Could you guide me? I’ve never done this and don’t know where to start:function category_head_hook () { if (is_category ('category-slug')): // Head of categories ?> <script> my ads code </script> <script> my analytics code </script> <? php endif; } add_action ('wp_head', 'category_head_hook', 10)
I would give them the link, but I am working on localhost.
I greatly appreciate your help! If they could guide me or tell me where to study, they would help me a lot
Greetings and thank you very much!
- The topic ‘Insert a different code in the head of home, category and post’ is closed to new replies.