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


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)

The topic ‘Output custom page CSS to header’ is closed to new replies.