Loading scripts only if a particular shortcode or widget is present

I needed a way to filter a page/posts content before it was loaded so I could add scripts to the header if a specific shortcode was present. After much searching I came across this on http://wpengineer.com function has_my_shortcode($posts) { if ( empty($posts) ) return $posts; $found = false; foreach ($posts as $post) { if ( … Read more

Between functions.php (theme), widgets, and plugins, which is loaded first?

Customer asks if a specific carousel plugin he uses can be widgetized. That means I should create a widget inside functions.php which calls the plugin’s function. That means that the plugin’s code has to be loaded first so that the function be available to WordPress when the functions.php file is loaded, right? Would that work? … Read more

Where to put my code: plugin or functions.php?

Is there an easy to understand scheme to decide what kind of code belongs to a plugin or the theme’s functions.php? There are many cases and many debates about that topic, mostly because there are some misconceptions about the inner workings of WordPress. I am asking for an answer based on facts, not on opinions. … Read more