questions

php function to change css

Rate this post

I’m trying to add a piece of code to change css on a page. I added the code to functions.php in WordPress. However, it does not seem to work. Since I’m quite new to this there might be something quite basic wrong with the code… Any idea why it might not be working?

// This code is added to functions.php
// intro is the class name of the element I'm trying to change
add_action( 'intro', function () {
    if ( is_user_logged_in() ) {
        ?>
            <style>
                display: none!important;
            </style>
        <?php
    };
    exit;
});

 

✔️Solution:

I got it to work by removing exit; and targeting an element:

add_action( 'wp_head', function () {
    if ( is_user_logged_in() ) {
        ?>
            <style>
                .intro{
                    display: none!important;
                }
            </style>
        <?php
    };
});

Leave a Reply

Your email address will not be published.

Back to top button