Diemension9

  • News
  • Linux
  • Fuckipred
  • Tiny gems
  • Htc Hero
  • Downloads
  • [wordpress] not loading scripts/styles in admin-interface

    i was writing a plugin for wordpress and realized the js and css files was growing to hell. tried to find some way to keep em from loading when the user was in the admin-interface but couldn’t find The Right Way™ to do it. so i sat down and went through the list of actions on the wordpress codex page. the only action before wp_print_styles/scripts i could find that didn’t fire when browsing the site (even if logged in) but did in the admin-interface was _admin_menu. so, if you wanna keep your plugins, themes or whatevers scripts/styles from loading when the user is browsing h(i|er)s admin-interface you can use something like this:

    function load_styles()
    {
        // register and enqueue your styles
    }
    function load_scripts()
    {
        // register and enqueue your scripts
    }
    function dont_load_anything()
    {
        remove_action('wp_print_styles', 'load_styles');
        remove_action('wp_print_scripts', 'load_scripts');
    }
    add_action('wp_print_styles', 'load_styles');
    add_action('wp_print_scripts', 'load_scripts');
    add_action('_admin_menu', 'dont_load_anything');

    // sluggo

    Posted

    2011-08-12 #

    Filed under

    Tiny Gems

    Tags

    action, add_action, php, plugin, remove_action, theme, widget, wordpress, wp, _admin_menu

    no comments

Top