mardi 5 janvier 2016

Is there an alternative way to pass a variable as a parameter for the is_page() function in WordPress?

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 the form, I wanted to use the is_page() function, passing the $page_selected variable as a parameter, doing as follows:

function my_custom_tooltip() {
     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 );
} 
if (  is_page($page_selected) ) : add_action('wp_enqueue_scripts', 'my_custom_tooltip'); endif;

Unluckily I found out that is not possible to do so, since the is_page() function does not accept a variable as a parameter. 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?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire