Grow your CSS skills. Land your dream job.

Using PHP to hide a div element on a certain page

  • # May 3, 2013 at 9:38 am

    Hi all,

    I was wondering if there is a way to use PHP to hide a div element on a certain page. (I’m using WordPress). I know the quick and easy way is this…

    php if(is_page(50) {
    style type=”text/css”
    #hidethisdiv {
    display: none;
    }
    /style
    php } else { };

    However, I need to hide it completely, in other words, hide it from the source code as well. Does anyone know how I can accomplish this?

    I know the code is messed up above, but for some reason I coudln’t get the code to display properly here in the forums.

    # May 3, 2013 at 10:27 am

    … if you want to remove the div entirely why not just use something like this:

    < ?php
    if(is_page(‘hide_here’)) {
    //don’t do anything
    } else {
    echo ‘

    Stuff

    ‘;
    }
    ?>

    # May 3, 2013 at 10:28 am

    I tried, but for some reason I tried to use the code on a post in WordPress and it didn’t work.

    I know WordPress has support forums but I have gotten 0 responses about this, so thought I’d try here.

    # May 3, 2013 at 10:31 am

    Basically what I’m trying to do is put this:
    http://www.singleinstilettos.com/get-married-in-a-year-lori-bizzoco

    on the homepage
    http://www.singleinstilettos.com

    I have a wordpress query code, however I needed to just display everything that is just in the blue border. So I figure the only way to do that was to add an exception code in the post…but it wasn’t working when I queried.

Viewing 4 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic.

*May or may not contain any actual "CSS" or "Tricks".