Jump to content

how can i display a div if the page is homepage, search page or single page of wordpress theme.


adamsevera
Go to solution Solved by maxxd,

Recommended Posts

I want to display a div if the page is homepage, search page or single page of wordpress theme.

 

what would be the proper syntax for it? currently i am doing the following which i think is obviously the least ideal way to do this :P

<?php if ( is_home()) { ?>


    <div class="container">

    </div>
 

<?php } ?>

<?php if ( is_home()) { ?>


    <div class="container">

    </div>
 

<?php } ?>

<?php if ( is_home()) { ?>


    <div class="container">

    </div>
 

<?php } ?>
Link to comment
Share on other sites

Oops sorry wrong code this is what i am currently using

<?php if ( is_home()) { ?>
    <div class="container">
    </div>
<?php } ?>

<?php if ( is_single()) { ?>
    <div class="container">
    </div>
<?php } ?>

<?php if ( is_page()) { ?>
    <div class="container">
    </div>
<?php } ?>
Link to comment
Share on other sites

  • Solution

You can shorten it a bit like so:

<?php
if( is_single() || is_home() || is_page() ):
?>
	<div class='container'></div>
<?php
endif;
?>

Or you can just put the div in the template pages controlling those particular pages. I think (off the top of my head, so check the template hierarchy on the WordPress site), you'd be looking at index.php for the blog (home) page, single.php or page.php for the other two. I haven't had my second cup of coffee yet and just logged on at work, so I may be mistaken about which files you'll need to target.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.