Skip to main content

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).

./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 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!

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 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!

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 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!

deleted 6 characters in body
Source Link
ralphjsmit
  • 402
  • 6
  • 23

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!

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!

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 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!

Source Link
ralphjsmit
  • 402
  • 6
  • 23

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

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!