Support » Requests and Feedback » Proposition and petition for new function

  • Resolved GalinaBublik

    (@galinabublik)


    I have proposition and petition.

    I added font-awecome.css to me theme.
    After some time added plugin and seen that plugin add font-awecome.css too.

    I think in WordPress need function that check list of registered style.

    In theme and/or in plugins developer can use some like this:

    if( !has_enqueue_style('font-awecome') ){
        wp_enqueue_style('font-awecome', get_template_directory_uri() . '/css/font-awesome.min.css');
    }
Viewing 4 replies - 1 through 4 (of 4 total)
  • Moderator Andrew Nevins

    (@anevins)

    The handle is an arbitrary name, so you’d have to first ensure plugins and themes use consistently named handles. That isn’t practical.

    Moderator Steve Stern

    (@sterndata)

    especially when one spells the handle incorrectly 🙂

    Look into the scripts/styles and dependencies (in general) API, there are already functions for this.

    
    if ( !function_exists('has_enqueue_style') ) :
    function has_enqueue_style($handle) {
        return wp_style_is($handle, 'enqueued');
    }
    endif;

    For scripts, you should use wp_script_is. enqueued is an option that checks if the script is queued and you have other options which you can see in the switch cases here in the source https://developer.wordpress.org/reference/classes/wp_dependencies/query/#source

    It makes sense to use wp_deregister_style to unregister a stylesheet and register it again the way you want, but keep in mind that you need to hook into plugins_loaded or plugin hooks because plugins happen to be loaded after the theme.

    Thank you, @samuel Elh, very match!

    • This reply was modified 5 days, 2 hours ago by GalinaBublik.
Viewing 4 replies - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.