Inject code into <head> per post?

Hi! I am trying to figure out how to inject custom code into the <head> section per post. All of the plugins I’m looking at seem like they just do it site wide with per post exceptions. I need the opposite of that.

I can write one if I need to but am trying to avoid it if I can.

5 Comments
  1. If you’re comfortable with PHP you could probably write this using conditionals either in functions.php or in header.php.

  2. Use wp_head action

    function inject_code_per_post() {
    // Your custom post head injection code
    }

    add_action( ‘wp_head’, ‘inject_code_per_post’);

  3. I should add that I want to customize what gets injected on each post. Ideally there is a snippet field on each post that I can customize.

 

This site will teach you how to build a WordPress website for beginners. We will cover everything from installing WordPress to adding pages, posts, and images to your site. You will learn how to customize your site with themes and plugins, as well as how to market your site online.

Buy WordPress Transfer