Advertisement
Guest User

WordPress: Only load css on custom post type edit page

a guest
Apr 14th, 2011
353
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // stylesheet used by all similar meta boxes
  2. add_action('admin_init','mb_enqueue');
  3. function mb_enqueue() {
  4.   // Get the globals that tell us where we are in the admin.
  5.   global $pagenow, $typenow;
  6.   // Sometimes $typenow is not available, so let's check and get it if needed.
  7.   if (empty($typenow) && !empty($_GET['post'])) {
  8.     $post = get_post($_GET['post']);
  9.     $typenow = $post->post_type;
  10.   }
  11.   // Only show our scripts on the admin pages they are used on to prevent possible conflicts with other scripts.
  12.   if (($pagenow == 'post.php' || $pagenow == 'post-new.php') && $typenow == 'portfolios') {
  13.     // WP Alchemy Stylesheet
  14.     wp_enqueue_style('custom_meta_css', _TEMPLATEURL . '/lib/admin/metaboxes/mb_style.css');
  15.     // WP Alchemy related JS
  16.     wp_register_script('my-custom_meta_js',  _TEMPLATEURL . '/lib/admin/metaboxes/mb_global.js', array('jquery','media-upload','thickbox'));
  17.     wp_enqueue_script('my-custom_meta_js');
  18.   }
  19. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement