Check if it’s a blog post or page in WordPress

1) Check Page type using is_page() function

if(is_page()) {
 echo "This is a PAGE.";
 }   

2) Check Page using get_post_type() function

if(get_post_type() === 'page') {
 echo "This is a PAGE.";
 }    

3) Check Page using post() function

if(get_post()->post_type === 'page') {
 echo "This is a PAGE.";
 }   

4) Check Post type using is_single() function

if(is_single()) {
 echo "This is a POST.";
 }  

5) Check Post type using get_post_type() function

if(get_post_type() === 'post') {
 echo "This is a POST.";
 }   

6) Check Post type using get_post() function

if(get_post()->post_type === 'post') {
 echo "This is a POST.";
 } 

Leave a Comment

Your email address will not be published. Required fields are marked *