I want to add a stylesheet for the options_page of my plugin only. But how to do that? My code so far:
function add_options_page_style() {
wp_register_style('options_page_style', plugins_url('css/options_style.css',__FILE__));
wp_enqueue_style('options_page_style');
}
add_action( 'admin_menu', 'add_options_page_style' );
I could place an if statement before the line with add_action...
but I’m not sure how to filter my options page. I already tried the $pagename
variable and also this line: $wp_query->queried_object->post_name;
but it didn’t work.
The filter $_GET['page']
does work but might break in future versions.
Somewhere you’ll be registering page like this:-
And while enqueueing script you’ll do something like this:-
add your page slug as suffix to
toplevel_page_
e.g. if page slug is this-plugin-options
then
here is wordpress doc with
Example: Load CSS File on All Admin Pages,
Example: Load CSS File from a plugin on specific Admin Page