0

Is it possible that additional CSS that we add in customizer section, display somewhere else instead of head? I am using twenty-seventy theme. I know its fetch and rendering code is available in wp-include/theme.php something like this

function wp_custom_css_cb() {
    $styles = wp_get_custom_css();
    if ( $styles || is_customize_preview() ) :
        $type_attr = current_theme_supports( 'html5', 'style' ) ? '' : ' type="text/css"';
        ?>
        <style<?php echo $type_attr; ?> id="wp-custom-css">
            <?php echo strip_tags( $styles ); // Note that esc_html() cannot be used because `div &gt; span` is not interpreted properly. ?>
        </style>
        <?php
    endif;
}

But i wish i remove this from head and add in some other separate file.

2
  • The simplest thing to do would be to make a child theme and put the extra CSS in there, assuming that you don't need to keep editing this from the admin site and you don't have a plugin that's generating extra custom CSS dynamically. If you really did want to serve it from a static file then you could hook the functions in theme.php to save it to a file on disk when the custom_css post is written and include a link to that instead, but that seems like a lot of work and wouldn't support plugins adding custom CSS dynamically.
    – Rup
    Commented Sep 11, 2020 at 23:47
  • Or you could add a PHP endpoint that serves the custom CSS and link to that too I suppose, but then you'd be loading the whole of WordPress an extra time per page so that doesn't seem worth it.
    – Rup
    Commented Sep 11, 2020 at 23:49

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.