I am working with wordpress shortcodes. After creating a few shortcode, all my shortcodes add
<style>
// all code
</style>
and I have realised its adding a lot of extra code, since this CSS depends on the shortcode variables I have to use <style>
.. what would be the best way to combine all the CSS <style></style>
generated from the shortcodes used on any page and then add them to page <head>
tag, instead of adding many <style>
tags..
I was thinking to add $GLOBALS['custom_css'] .= 'css for each shortcode'
; and then display it in header.php
file..
Is this a good idea ? any insight would be highly appreciated as I want to make my code look clean and neat..
Is your CSS consistent enough across the shortcodes to add it to one external file and load it with wp_enqueue_style when the shortcode is run? This way, it won’t load if you’re not using the shortcode, and if you are running it multiple times, it will only load once.
http://codex.wordpress.org/Function_Reference/wp_enqueue_style