This looks almost correct. Let’s have a look at is_single()
:
Works for any post type, except attachments and pages…
So if the given ID isn’t that of a page
or attachment
post type then you can use the function as so:
if( is_single( 2578 ) ) {
/* ... */
} else {
/* ... */
}
Otherwise, if the ID is a page
post type you can use is_page()
if( is_page( 2578 ) ) {
/* ... */
}
Should the ID be that of an attachment
page you may use is_attachment()
if( is_attachment( 2578 ) ) {
/* ... */
}
Finally, if you’re unsure of the post type you could check against the global $post
object, assuming it is correct:
global $post;
if( is_object( $post ) && 2578 == $post->ID ) {
/* ... */
}
Related Posts:
- Custom SQL query to get List of posts with featured image url
- the_post_thumbnail() based on the Post ID
- Insert After Second Paragraph Without Tag?
- Get_the_author doesn’t return author name
- Link for Most Recent Post
- Using loop pagination on single.php
- single.php with different look by category
- Check If Post Was Published More Than 6 Months Ago Using get_the_date
- How to present a div only when the index.php is accessed for/by the single post pages
- how to make an array of post id’s in is_single
- Pagination in single.php
- Limit the number of characters/words in an excerpt for a related posts section
- My single.php page skips the first div tag
- How to center all text body in single.php at once?
- LinkedIn Share Post Button
- Post Thumbnail on Single (if elseif else)
- Custom single.php files for different post formats
- Shortcode Displays 2 times
- Setting $_SERVER[‘HTTPS’]=’on’ prevents access to wp-admin
- Enforcing password complexity
- Check if a menu is empty?
- Adding a search form inside a div
- How To Make Connection To WordPress Data Base In A Plugin?
- Dynamically change feature image in customiser
- Walker class: Problems with understanding how walk() method can be called without error
- How to get the post count for the last x days filtering by categories
- How to create shortcodes that pull custom field data from general settings
- Where exactly do I write define( ‘WP_DEBUG’, true ) in wp-config file
- Getting a fatal error while updating
- How to display related posts from parent category
- File upload, uploads only file name
- WordPress 3 – how are passwords stored and how do I compare to them?
- Use is_product_category() properly
- How can I add tinymce editor in WordPress with jQuery?
- Double or Single Quotes in WordPress Content Conflicting With HTML
- How can i display post loop in table format?
- list posts and wrap them alphabetically A-Z
- Changing Woocommerce flat rate every nth number of items
- Link to the parent post in attachment page
- Convert all images to PNG on file upload
- HTML tags in bloginfo description
- WordPress 5 WP REST routes – No errors
- Using fwrite() and “a” appends multiple times instead of once
- Add prefix to link url
- Selectbox in admin panel function linking to CSS
- wordpress allow user to edit user profile with custom fields
- Making BuddyPress Activity Stream (Post Type) Featured Images Clickable [closed]
- WordPress admin dashboard missing icons
- Which field should I edit to make the checkbox marked by default?
- Add filter when image is uploaded?
- How can I save unique user data on my site? [closed]
- Add New User, extra fields which are required?
- Keyword checking in Gravity Forms
- Get URL Parameters from referer
- Using custom tables for old posts
- Adding logo to WordPress header
- Is the wp_enqueue method efficient?
- Making an AJAX call to refresh a table
- How does WP work in conjunction with a web server?
- add_filter only for front office
- WordPress and MySQL: trying to print data using PHP from user_meta custom field data
- Form Submission Not Working In Custom Theme
- Show metabox only for homepage
- Concatenate Custom Field Value & HTML Value
- How do I properly code my footer? See example
- Use of IF statement in Header file
- apply_filters with several different values?
- Advanced Query posts
- Triggering a timewall after X days
- Bootstrap 4 Carosuel with ACF Repeater field
- How to preload header logo image in WordPress? like what’s the code and where do I put it?
- echo cutom css code to WordPress page template file ? is this safe?
- PHP `iconv` not working inside a WordPress site
- How to make a “page-option” in WordPress
- Replacing entire tag with shortcode – JavaScript [duplicate]
- How do I visualize the author’s post from the front end?
- How to add a full working piece of website already coded, to a large scale Website design project?
- How do if all posts has this category ID then do this
- Query to show average # of months all accounts with specific role have been active
- Send email to users when they get new followers
- Use PHP to inject HTML into before page renders?
- Query doesn’t display text data with apostrophes
- WooCommerce Custom Tab with ACF Repeater Field
- My WP Website Shows HTTP ERROR 500
- add menu page in loop menu order
- Display product attributes for current product
- soap request in wordpress for a fedex pickup request [closed]
- Dynamically Create Posts Via XML File
- pages disable after wordpress update
- How to only fetch certain Tag ID’s
- Create server side text from wordpress page
- Make first child link default instead of its parent
- How to set a cookie based on a page Get variable?
- Editing the contents of just one div on a page from wordpress
- How to change the menu color
- Display latest 5 posts on homepage
- I want Page titles and excerpts to show up on home.php in certain order
- Advanced custom fields Repeater conditional statement not working [closed]
- running an existing WordPress site from Visual Studio Code?
- get_post_meta returns on side but it doesn’t return on bottom of admin page