I am trying to add a style to the header, using this method the style only loads on single posts but if I use a shortcode to load the post content that style does not load in the header:

add_action( 'wp_head', 'output_styles')
function output_styles($base_ID){
   $global post;
     echo '<style type="text/css">'. get_post_meta($post->ID, 'append_css') .'</style>';
}

in my shortcode I am passing the ID of the post, if I call the ouput_styles functions from shortcode function :

output_styles($pass_id);

then the content of output_style is printed but it is not in the header.

How can I output the style in the header when using shortcodes?

Read more here: Add inline style to pages where shortcode was used


Solution:

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: