This question already has an answer here:
I'm trying to add CSS to wp_head, from within the method called to render a shortcode. I know that wp_head does not take any parameters, so I'm trying to figure out the following:
The method called by WP to render the shortcode has two params, $atts and $content. What I'm trying to do is generate instance specific CSS from the $atts provided, and add it to the header, rather than rendering a tag in my method, I'd like all of my CSS in one spot (I'm adding a numerical ID to each rule, which allows custom CSS even if its the same shortcode).
The troubles I'm having:
- I can't just pass a string to wp_head using add_actionm it requires a function
- Because I need the $atts provided by wordpress, the function has to accept a parameter, which php 5.2 doesn't support (minimum supported php version for WP).
- WP doesnt have a way to called something like.. content_for in rails, so I cant just append it and put it where I want.
I've tried filters, actions, *wp_add_inline_styles*, and even globals with no success. Any help would be greatly appreciated.