How do I adapt this solution to work with my plugin? (Please see the link).
I enqueue my css and js script as follows:
function my_plugin_init() {
wp_enqueue_script('my_plugin_script', plugins_url('js/the_filepath.js', __FILE__), array('jquery'));
wp_enqueue_style( 'my_plugin_css', plugins_url( '/css/the_filepath.css', __FILE__ ) );
}
add_action('init', 'my_plugin_init');
I tried putting this in the theme’s functions.php, but it didn’t work:
function remove_my_plugin_extras() {
remove_action('init', 'my_plugin_init');
}
if( !is_page('My_Page') ) {
add_action('wp_head', 'remove_my_plugin_extras');
}
The script and css still loaded. How do I adapt the solution in this case?
The right hooks
*) Read this article @wpdevel.
Further reading in the Codex about the three hooks
On the
admin_enqueue_scripts
hook, you have an argument as well: The$hook_suffix
:Admin page hooks
When registering a admin (sub)menu page, you can save the result, which is the page hook, into a variable:
Admin globally available variables to check against
The following
are available on a wide range of admin pages. Use them to check if you’re on the requested page that you need and only then do stuff.
Even better than testing against a variable, which can get reset on the fly (example) …
… is using the
WP_Screen
object on admin pages: