[wp-hackers] Remove wp_enqueue_style called mid-page

Nikola Nikolov nikolov.tmw at gmail.com
Wed Mar 26 16:03:30 UTC 2014


Hi Dino,

Have you tried simply enqueueing that style? In theory WP shouldn't render
the same style/script twice.

function my_enqueue_plugin_style() {
    wp_enqueue_style( 'plugin-style' );
}
add_action( 'wp_enqueue_scripts', 'my_enqueue_plugin_style' );

If the plugin doesn't register the style all the way until it's enqueued,
then it'd be a bit more tricky, but something like this should work:

function my_dequeue_plugin_style() {
    wp_dequeue_style( 'plugin-style' );
}
add_action( 'wp_footer', 'my_dequeue_plugin_style' );

function my_enqueue_plugin_style() {
    wp_enqueue_style( 'plugin-style', $url_to_plugin_css_file );
}
add_action( 'wp_enqueue_scripts', 'my_enqueue_plugin_style' );

Nikola


On Wed, Mar 26, 2014 at 5:58 PM, Dino Termini <dino at duechiacchiere.it>wrote:

> Hi all,
>
> I am using a plugin that does a wp_enqueue_style mid-page, instead of
> using the appropriate hook. This causes the CSS to be added to the footer,
> which I would like to avoid.
>
> Aside from contacting the plugin author, is there a way to dequeue that
> style so that I can enqueue it in the header? I would like to avoid editing
> the plugin's source code to comment out that line of code ;)
>
> I've tried a bunch of combinations of actions/dequeue/deregister, to no
> avail.
>
> Thanks,
> Dino.
> _______________________________________________
> wp-hackers mailing list
> wp-hackers at lists.automattic.com
> http://lists.automattic.com/mailman/listinfo/wp-hackers
>


More information about the wp-hackers mailing list