My problem is that I use dynamic css file in the WordPress theme that is loaded with Ajax. However, it loads this same dynamic css file for backend also. How do I modify my code that it loads dynamic css file only for frontend, not for the backend. Here’s my code:
wp_enqueue_style('dynamic-css',
admin_url('admin-ajax.php?action=dynamic_css'));
function dynaminc_css() {
require(get_template_directory().'/dynamic-css.php');
exit;
}
add_action( 'wp_ajax_dynamic_css', 'dynaminc_css' );
add_action( 'wp_ajax_nopriv_dynamic_css', 'dynaminc_css' );
}
Here’s a working example with inline comments:
The
is_admin()
function is what you are looking forAnything inside there will only execute if not in the administration panel.
http://codex.wordpress.org/Function_Reference/is_admin