wp_enqueue_style for plugin options page
-
16-10-2019 - |
Pergunta
I'm trying to add a stylesheet to the options page for my plugin - code looks like this:
add_action( 'admin_print_styles-rps-paypal', 'rps_paypal_add_css' );
function rps_paypal_add_css() {
wp_enqueue_style( 'rps_paypal', plugins_url( '/rps_paypal/css/rps-paypal.css' ) );
}
add_action( 'admin_menu', 'rps_myplugin_add_page' );
function rps_myplugin_add_page() {
add_options_page(
'My PayPal Plugin',
'My PayPal Plugin',
'manage_options',
'rps-paypal',
'rps_myplugin_option_page'
);
}
Can't figure out why it's not showing up...
Solução
the call to add_options_page will return the string literal to use for your RSS, so it should look something like this:
$page = add_options_page( ... );
add_action( 'admin_print_styles-' . $page, 'rps_paypal_add_css' );
More info here: http://codex.wordpress.org/Function_Reference/wp_enqueue_style
Outras dicas
First I am not sure you get hook suffix right. It is return of add_options_page()
function and from quick test should be something like admin_page_rps-paypal
in your case. But really you should save that return in the variable and use that rather than hardcode it.
Second your plugins_url()
usage is little off, your plugin's folder name is not guaranteed to be that. More robust to use it like:
plugins_url('/css/rps-paypal.css', __FILE__);