admin-ajax.php slow website, how to fix


I have a function in my wordpress that load a dynamic css. I checked that this admin-ajax.php call made the website slow (+5s) about.

add_action( 'wp_enqueue_scripts', 'theme_custom_style_script', 12 );

function theme_custom_style_script() {
    wp_enqueue_style( 'dynamic-css', admin_url('admin-ajax.php').'?action=dynamic_css', '');

add_action('wp_ajax_dynamic_css', 'dynamic_css');

function dynamic_css() {
    require( get_template_directory().'/css/custom.css.php' );

Can i save the output of this file in a folder each time i make an edit on admin , and load such a css link instead of load everytime via admin-ajax ? or call in different way to avoid this issue ?

user3309614 2 months 0 Answers 7 views 0

Leave an answer