Put CSS inside a PHP file and include it the right way

Question

I want to put CSS inside a PHP file, because with that I can use ‘conditional CSS’, depending on the value of a customizer control.

My idea is to create a new php file, somewhere in my theme directory (./assets/css/header-conditional-styles.css).

In this file I have created the following code:

<?php header("Content-type: text/css; charset: UTF-8"); ?>


<style>

    <?php if ( text == get_theme_mod( 'layout_logo', text ) ) : ?>
        .theme-header-title { color: green !important; }
    <?php else : ?>
        .theme-header-title { color: blue !important;}
    <?php endif; ?>

</style>

The code inside the is as an example.

In my functions.php file I tried to include the file like this:

require( get_template_directory()  . '/assets/css/header-conditional-styles.php');

I implemented this and I know have great difficulty editing theme files. It gives me the message that my changes might not be saved and that I might try to upload them via FTP. Please point me in the right direction on how to include the file and if the content of the php-file is correct? Thanks!

0
, , , , ralphsmit 2 years 2020-01-04T08:38:49-05:00 0 Answers 88 views 0

Leave an answer

Browse
Browse