Sviat Kuzhelev
Sviat Kuzhelev

Reputation: 1788

Make the condition to hide header on child pages Wordpess

I ran into the problem of hiding the header on the pages of a particular directory on WordPress CMS.

Is it possible to make an php-code condition that will be do not show the header on all pages in some directory by condition:

like

<?php if( $some_page => have 'users' in $url ) : ?>
    <header style="display:none"></header>
<?php else......
<?php endif....

P.S.

I know about a great pluging for css magic on any page, but I have a too many pages...

Upvotes: 0

Views: 138

Answers (3)

Sviat Kuzhelev
Sviat Kuzhelev

Reputation: 1788

I found a simple solution for this:

We can make a simple search in the url on the symbol or phrase in it, by stristr() func. So the condition will be next:

<?php $current_page = get_page_link() ?>

<?php if (stristr($current_page, "user") == true) : ?>              // if "url" have 
    <h1 class="entry-title h1" style="display:none;"></h1>          // phrase 'user' 
<?php else : ?>                                                     // in it the header will not show
    <?php the_title( '<h1 class="entry-title h1">', '</h1>' ); ?>   // header 
    <h1 class="entry-title h1"></h1>                                // show without any problem
<?php endif; ?>

Upvotes: 1

Krishnadas PC
Krishnadas PC

Reputation: 6539

I have made some edits in your answer.

    <?php $current_page = get_page_link() ?>

    <?php if (stristr($current_page, "user") === false) : ?> 
    <?php the_title( '<h1 class="entry-title h1">', '</h1>' ); ?>   
    <?php endif; ?>
//If you don't want to render anything on true condition no need to render anything.

Use === for checking the types as well.

Upvotes: 0

Ylama
Ylama

Reputation: 2489

CSS solution

Lets say your homepage body class : <body class="index"> and your header <header class="page-header">text</header>

You could use this class for displaying header or not , using this method.

body:not(.index) .page-header { display: none; }  

Hope it helps.

Upvotes: 1

Related Questions