Is there a way to put some code into the header but have it load only on blog posts?
Maybe a plugin or a piece of code that could help me accomplish this?
Yes. In your functions.php
file, add something like the following:
function my_post_header_function() {
if( is_single() ) {
// Your Code Goes Here
}
}
add_action( 'wp_head', 'my_post_header_function' );
What this will do is execute this when wp_head()
is fired. It will see if you're on a single post (NOTE: This will not work on pages or attachments) and if you are, it will execute the code you want to put.
You could create another header called header-blog.php
Then on your blogs template replace the
<?php
get_header();
?>
with
<?php
if ( is_home() ) :
get_header( 'blog' );
else
get_header();
endif;
?>
I know is_home is slightly confusing but this is what wordpress looks for as a blog page
also see https://codex.wordpress.org/Function_Reference/get_header
header.php
file for only inserting a few lines of extra code. Plus it adds some maintainability problems down the road.