How to determine if content is a post or page in WordPress

I’m working on a WordPress site and need to figure out how to tell the difference between posts and pages programmatically. I want to add some custom functionality that behaves differently depending on whether the user is viewing a regular blog post or a static page.

I’ve been looking through the WordPress documentation but I’m not sure which functions or methods I should use to make this check. Is there a built-in WordPress function that can help me identify the content type? I need this to work reliably across different themes and setups.

Any suggestions on the best approach to accomplish this would be really helpful. Thanks in advance for any guidance you can provide!

hey there! if ur lookin to check if its a post or a page, just use is_page() for pages and is_single() for posts. super simple, just add it in the template or functions.php file. has worked for me without any issues across themes!

I’ve used $post->post_type for years and it’s been rock solid. You can grab it globally with global $post; echo $post->post_type; or use get_queried_object()->post_type for archive pages. It gives you direct access without function overhead and works even when conditional functions act weird. Really handy for custom shortcodes or AJAX requests where WordPress’s query context isn’t fully loaded yet.

I always use get_post_type() - it returns the exact post type and works everywhere, whether you’re in the loop or not. Just call it like get_post_type() === 'page' or get_post_type() === 'post' for your checks. I’ve used this method for years across tons of client sites and it’s never let me down, even with custom post types or weird theme setups. It’s especially handy in widgets where the usual conditional tags can get flaky.