Created
July 14, 2016 09:09
-
-
Save digamber89/13fff2d1dedefddf6c23d82fa27891b9 to your computer and use it in GitHub Desktop.
Correct way to enqueue styles and scripts for your plugin option pages
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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