Skip to content

Instantly share code, notes, and snippets.

@digamber89
Created July 14, 2016 09:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save digamber89/13fff2d1dedefddf6c23d82fa27891b9 to your computer and use it in GitHub Desktop.
Save digamber89/13fff2d1dedefddf6c23d82fa27891b9 to your computer and use it in GitHub Desktop.
Correct way to enqueue styles and scripts for your plugin option pages
// Load the scripts conditionally
add_action( 'load-' . $menu_page, array($this, 'enqueue_scripts') );
/* This function is only called when our plugin's page loads! */
public function enqueue_scripts(){
add_action('admin_enqueue_scripts', array($this, 'load_admin_scripts') );
}
/* Load Scripts only if necessary */
public function load_admin_scripts(){
wp_register_script(
'wcpe_scripts',
plugins_url('/assets/js/wcpe_scripts.js', WCPE_FILE_PATH ),
array('jquery'),
1.0,
true );
wp_register_style(
'wcpe_scripts',
plugins_url('/assets/css/wcpe_style.css', WCPE_FILE_PATH ),
'',
'',
'ALL' );
wp_enqueue_style('wcpe_style' );
wp_enqueue_script('wcpe_scripts');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment