Hi Forks, Today i am telling about WordPress conditions, There are a lot of different conditional tags to use when working with WordPress templates or theme files. To target specific pages by body class, or an archive for a clicked tag or category keep on reading. This is how to use conditional tags to target archives, tags, categories or any other type of page in WordPress.
Check if is page archives > Any tag
Meaning if user clicked on any tag and is now on the archives page
<?php if (is_tag()) : ?> // your code <?php endif; ?>
Check if is page archives > Some tag
Meaning if user clicked on a tag and is now on the archives page of that tag.
<?php if (is_tag('Some tag')) : ?> // your code <?php endif; ?>
Check if is page archives > Any category
Meaning if user clicked on any category and is now on the archives page
<?php if (is_category()) : ?> // your code <?php endif; ?>
Check if is page archives > Some category
Meaning if user clicked on a category and is now on the archives page of that category.
<?php if (is_category('Some category')) : ?> // your code <?php endif; ?>
Other conditional tags to target specific pages in WordPress:
Check if is page by Page ID
Meaning if is page with ID 45
<?php if (is_page(45 )) : ?> // your code <?php endif; ?>
Check if is page by template
Meaning if page is using a special template
<?php if ( is_page_template( 'my-template.php' ) ) : ?> // your code <?php endif; ?>
Check if is page is a single post
Meaning if user click to open a single post on its own page
<?php if (is_single()) : ?> // your code <?php endif; ?>
Check if is page is a single post displaying post with ID 45
Meaning if user click to open a single post on its own page, and this post hade id 45
<?php if (is_single('45')) : ?> // your code <?php endif; ?>