Limit enqueuing admin CSS and JavaScript to plugin's admin pages only please.
-
In your code you have this:
if (is_admin()) { function cf_add_style() { wp_enqueue_style('form1_style1_sheet1', plugins_url('css/fgstyle.css', __FILE__)); wp_enqueue_style('mg_admin_stylesheet', plugins_url('css/mgstyle.css', __FILE__)); } add_action("admin_head", "cf_add_style"); function wordpress_style() { wp_enqueue_style('stylesheet_menu', admin_url('load-styles.php?c=1&dir=ltr&load=admin-bar,wp-admin,buttons,wp-auth-check&')); wp_enqueue_style('style_menu', admin_url('css/colors-fresh.min.css')); } add_action('admin_head', 'wordpress_style'); }
Please limit the enqueuing of the plugin’s CSS to it’s own admin pages. This is breaking the admin style of many plugins because they are being enqueued out of order which causes undesirable effects for many other plugins.
Also, this is not correct:
if (isset($_GET['page']) == 'cf_page' || isset($_GET['page']) == 'cf_mg_page') { add_action('init', 'cf_embeded_script'); }
Any admin page where $_GET[‘page’] isset *will* have the javascripts enqueued. This means the plugin’s javascripts files will also not be limited to its own admin pages. They will be enqueued on all admin pages where the
page
query var is set. The code should be this to work correctly:if ( ( isset($_GET['page']) && $_GET['page'] == 'cf_page' ) || ( isset($_GET['page']) && $_GET['page'] == 'cf_mg_page' ) ) { add_action('init', 'cf_embeded_script'); }
Thanks for your time and consideration of these changes! They will be to a benefit to all your users!
- The topic ‘Limit enqueuing admin CSS and JavaScript to plugin's admin pages only please.’ is closed to new replies.