I am busy with a plugin that does a few shortcodes, my problem is in one of the shortcodes I keep track off different values each time the shortcode function gets executed and add them to a global variable.
I would like to be able to use the values stored in the variable in a style in the head. wp_head action does not work as when it execute it seems the shortcodes are yet to be parsed and then the variable is empty.
I have done a workaround where I output jQuery on my plugin class destruct to add the var in a style to the head but obviously this has a delay.
Any idea how I can achieve what I want?
Example code how it works now:
class myPlugin {
var $styleVar;
function __construct() {
add_shortcode('myshortcode', array($this,'my_shortcode'));
}
function __destruct() {
$this->load_head_style();
}
function my_shortcode( $atts, $content = '' ) {
//do shortcode parsing here and add to $stylevar array
}
function load_head_style() {
//output jQuery to enqueue style in head
}
}
$myPlugin = new myPlugin();