Support

Account

Home Forums Front-end Issues Output custom page CSS to header

Solved

Output custom page CSS to header

  • I am trying to output custom CSS and footer script for individual pages using textarea field type. I have added this code to the header.php file to start.

    if( get_field('custom_page_css')) {
    $customCss = the_field('custom_page_css');
       echo '<style type="text/css" media="screen">' . $customCss . '</style>';
    }

    The issue is, the css outputs outside the <style></style> tag.

    .acf-style { display:none; }
    <style type="text/css" media="screen"></style>
  • the_field() always echos the value of the field.

    
    $customCss = get_field('custom_page_css');
    if($customCss) {
       echo '<style type="text/css" media="screen">' . $customCss . '</style>';
    }
    
Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.

We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Cookie Policy. If you continue to use this site, you consent to our use of cookies.