I am creating a wordpress plugin from which user can select different styles from the plugin options panel. I want to enqueue css file via wp_enqueue_style()
according to the user input.
I am getting error when I want to get the metabox value inside the plugins php file.
Error Says:
Calling undefined variable $... on line no ..."
Is there any way I can get the value of the metabox inside php file and enqueue the appropiate css file according to the user input on dashboard.
I am using Custom-Metaboxes-and-Fields-for-WordPress plugin to retrieve user input from plugin option panel for this purpose
My code:
function easyloader_theme() {
global $post;
$theme = easyloader_get_option( 'easyloader_theme' );
wp_register_style('easyloader_style', plugins_url('themes/pace-theme-'. $theme .'.css',__FILE__),'','1.0.0.', false);
wp_enqueue_style('easyloader_style');
}
add_action( 'init', 'easyloader_theme');
I can easily get value of this user input in any when I paste this code in themes php file like (header.php, page.php, footer.php ) via
<?php global $post; $theme = easyloader_get_option( 'easyloader_theme' ); echo $theme; ?>
I just want to get the value inside my plugin php file not in the theme file.
The proper way to enqueue is with the following action:
Looks like the plugin has some internal cache, but at the end you can try using WP function directly: