How to load JS and CSS only on specific Pages using is_page()?
I am building my first WP plugin, it should load some JS and CSS files only on specific pages selected through a form available in the plugin Admin area. Once selected in the form, Page Title gets stored in the DB wp_options table, then the data is pulled back out in a variable named $page_selected. To load JS and CSS files only in the pages selected in form, I wanted to use the is_page() function, passing the $page_selected variable as a parameter.
function my_custom_tooltip() {
if ( is_page($page_selected) ) {
wp_enqueue_style( 'custom_tooltip_frontend_css', plugins_url('custom-image-tooltip/custom-image-tooltip.css') );
wp_enqueue_script( 'custom_tooltip_frontend_js', plugins_url('custom-image-tooltip/custom-image-tooltip.js'), array('jquery'), '', true );
}
} add_action('wp_enqueue_scripts', 'my_custom_tooltip');
Unluckily In my case that conditional statement doesn't work correctly. Is there any way to achieve the same result, matching the page selected in the form by the user with the current Page being displayed?
Topic wp-enqueue-script page-specific-settings pages Wordpress
Category Web