Categorie

Pubblicato il in How-To and Troubleshooting | 0 commenti

How to show elements only in posts on WordPress

How to show elements only in posts on WordPress

If you want to show elements only on your WordPress posts, and not elsewhere (home, pages, categories, etc.), just use the following code:

<?php if( is_single() ) : ?>

<!– YOUR CODE HERE –>

<?php endif; ?>

Here you have the full documentation of is_single() function:

is_single()

If instead you want to show your element / content only on other page types (category, archive, page, etc.), just pick the corresponding function from the list below and use it in place of is_single() in your code:

  • is_page ()
  • is_home()
  • is_tag()
  • is_search()
  • is_archive()
  • is_category()
  • is_front_page()

Finally, if you want to show your element / code for all the page types DIFFERENT from a specific one, just place a ! before the corresponding function:

<?php if( !is_single() ) : ?>

<!– YOUR CODE HERE –>

<?php endif; ?>

Pin It on Pinterest

Shares

Condividi: