Output Jigoshop Admin Styles and Scripts on Its Own Pages Only

I have seen a lot of complaints about Jigoshop outputting styles and scripts to all admin pages instead of doing so only on its own admin pages. This is a common problem among the WordPress community. It’s not a coincidence that one of the most offered suggestion to a problem is to turn off all your installed plugins, but that is a topic for another post.

I recently had to set up a store with Jigoshop and experienced the same problem. I had a couple plugins installed and their styles and scripts interfered with Jigoshop ones. So I decided I will unhook Jigoshop’s admin styles and scripts and hook them to my own action, which outputs them only to the correct pages.

Now, I will show you what I did and hopefully this will help to solve your issue.

Find the Jigoshop Admin Styles and Script Hooks

To find the admin hooks you need to look into Jigoshop directory for “jigoshop.php” file. Inside you will find

add_action('admin_print_scripts', 'jigoshop_admin_scripts');
add_action( 'admin_enqueue_scripts', 'jigoshop_admin_styles' );

responsible for outputting the admin styles and scripts.

Unhook and Hook Back

The trick here is to use the specific WordPress Hooks to output the styles on a specific admin page.
But first, find the “functions.php” file in your themes folder and open it in your favorite editor.
Then, go to the bottom (or where ever you feel like placing some code to) and we put this: ( bare with me, it seems like a lot of code, but it’s simple really)

if ( class_exists('jigoshop') ) {
//Remove the hooks
    remove_action( 'admin_enqueue_scripts', 'jigoshop_admin_styles' );
    remove_action('admin_print_scripts', 'jigoshop_admin_scripts'); 
//Add the styles to the Jigoshop pages
    add_action('admin_print_styles-toplevel_page_jigoshop', 'jigoshop_admin_styles');
    add_action('admin_print_styles-page_jigoshop_jigoshop_dashboard', 'jigoshop_admin_styles');
    add_action('admin_print_styles-jigoshop_page_jigoshop_settings', 'jigoshop_admin_styles');
    add_action('admin_print_styles-jigoshop_page_jigoshop_sysinfo', 'jigoshop_admin_styles');
    add_action('admin_print_styles-product_page_jigoshop_attributes', 'jigoshop_admin_styles');
    add_action('admin_print_styles-toplevel_page_product', 'jigoshop_admin_styles');
    add_action('admin_print_styles-product_page_jigoshop_attributes', 'jigoshop_admin_styles');
    add_action('admin_print_styles-product_page_jigoshop_attributes', 'jigoshop_admin_styles');
    add_action("load-post.php", 'jigoshop_admin_styles');
    add_action("load-post-new.php", 'jigoshop_admin_styles');
    add_action("load-edit.php", 'jigoshop_admin_styles');
    add_action("load-edit-tags.php", 'jigoshop_admin_styles');

//Add the scripts to the Jigoshop pages
    add_action('admin_print_styles-toplevel_page_jigoshop', 'jigoshop_admin_scripts');
    add_action('admin_print_styles-page_jigoshop_jigoshop_dashboard', 'jigoshop_admin_scripts');
    add_action('admin_print_styles-jigoshop_page_jigoshop_settings', 'jigoshop_admin_scripts');
    add_action('admin_print_styles-jigoshop_page_jigoshop_sysinfo', 'jigoshop_admin_scripts');
    add_action('admin_print_styles-product_page_jigoshop_attributes', 'jigoshop_admin_scripts');
    add_action('admin_print_styles-toplevel_page_product', 'jigoshop_admin_scripts');
    add_action('admin_print_styles-product_page_jigoshop_attributes', 'jigoshop_admin_scripts');
    add_action('admin_print_styles-product_page_jigoshop_attributes', 'jigoshop_admin_scripts');
    add_action("load-post.php", 'jigoshop_admin_scripts');
    add_action("load-post-new.php", 'jigoshop_admin_scripts');
    add_action("load-edit.php", 'jigoshop_admin_scripts');
    add_action("load-edit-tags.php", 'jigoshop_admin_scripts');
}

Let me explain a little bit of what happened here. Usually when you do this process you assign the return of “add_menu_page” hook to a global variable and then you attach the variable to the “admin_print_styles-” hook above, but because I did not want to touch anything inside Jigoshop files, I just plain wrote this return inside that hook.

End Notes

Because you just unhooked the Jigoshop styles the sidebar menu will look weird when you are not on Jigoshop pages. So, to avoid that, you want to make a small css file with the styles for the sidebar. Those styles you will find in the first few lines of “Jigoshop -> assets -> css -> admin.css” and they read something like this:


#toplevel_page_jigoshop .wp-menu-image{background:url(../images/icons/menu_icons.png) no-repeat 0 -32px!important}
#toplevel_page_jigoshop:hover .wp-menu-image,
#toplevel_page_jigoshop.wp-has-current-submenu .wp-menu-image{background:url(../images/icons/menu_icons.png) no-repeat 0 0!important}
#toplevel_page_jigoshop .wp-menu-image img{display:none}
#menu-posts-product .wp-menu-image{background:url(../images/icons/menu_icons.png) no-repeat -35px -32px!important}
#menu-posts-product:hover .wp-menu-image,
#menu-posts-product.wp-has-current-submenu .wp-menu-image{background:url(../images/icons/menu_icons.png) no-repeat -35px 0!important}
#menu-posts-shop_order .wp-menu-image{background:url(../images/icons/menu_icons.png) no-repeat -70px -32px!important}
#menu-posts-shop_order:hover .wp-menu-image,
#menu-posts-shop_order.wp-has-current-submenu .wp-menu-image{background:url(../images/icons/menu_icons.png) no-repeat -70px 0!important}

Changes the image path to match the one of the file and include it in the admin area for all pages


if ( is_admin() ) {
    wp_register_style('your_styles', path/to/your/file.css');
    wp_enqueue_style('your_styles');
}

All Done

That’s it, you are set. I know, it came to a big post, but it’s a couple of copy-paste procedures and create-include a css file. I hope you found this tip useful. If you have any comments or suggestion, or may be you found a mistake in the code or this did not work for, just post in the comments below.

Comments 3

  1. I do agree with all of the ideas you have presented in your post. They’re really convincing and will certainly work. Still, the posts are very short for novices. Could you please extend them a little from next time? Thanks for the post.

  2. I simply want to tell you that I’m very new to blogging and really savored this web-site. Very likely I’m going to bookmark your website . You definitely come with perfect articles and reviews. Thanks a lot for sharing with us your web-site.

Leave a Reply

Your email address will not be published. Required fields are marked *