I’m using the following code to place some page-specific scripts into my header in WordPress within functions.php. It’s including the code at the beginning of the header, but it needs to be loaded last in order for the page to work as it should. Is there a way to specify in the code that I want this php file to be included at the bottom of the header?
function my_post_header_function() {
if( is_single() ) {
include 'header-product.php';
}
}
add_action( 'wp_head', 'my_post_header_function' );
Note: I want it to be within the <head> </head>
tags still, but placed before the closing </head>
tag.
2
Answers
Due to the limitations of placement in functions.php I instead placed it within header.php before the closing
</head>
tag, as follows:Try changing the priority to something later. The default is 10, so try 20: