WordPress : If Statement with HTML and Includes

I want to include a different inline <style> tag that contains a php include in my wordpress header.php file based on wether it’s my blog or it’s a page.

in simple words i want my blog to have this in the <head>

Read More
<style type="text/css">
        <?php include '../css/1.css.php';?>
</style>

and i want my pages to have this other one in the <head>

<style type="text/css">
        <?php include '../css/2.css.php';?>
</style>

I’ve found this snippet and the distinction between blog and pages works, the problem is the include line

<?php
if(is_page()){
    echo 'Foo';
    include ('../css/above-the-fold-contact.css.php');
    echo 'Example: one';
}
else{
    echo 'Foo something else';
    include ('../css/above-the-fold-blog.css.php');
    echo 'Example: two';
}
?>

it does inject the right file in the right page, but I need to wrap the include around <style> tags, not doing so cause the content of the file to be injected as plain text. how do I do that? what’s the syntax? any help is really appreciated, thanks so much!

Related posts

1 comment

  1. <?php
        echo '<style type="text/css">';
    
        if( is_page() )  { include '../css/above-the-fold-contact.css.php'; }
        else             { include '../css/above-the-fold-blog.css.php'; }
    
        echo '</style>';
    

    EDIT : Just a quick mention – if your CSS is not generated dynamically, then there are better ways of doing this ( like wp_enqueue_style, for example )

Comments are closed.