I’ve been doing a lot of content management lately and that means managing larger back archives of web data used in content marketing. Over the course of time, things you might have wanted to happen in the past to every web post in WordPress may not always apply in the present or the future. When it’s a rare occurrence, such as when you don’t want a particular thing to display on a particular post that displays everywhere else, you’ll need to make an exception loop for that post in the single.php file.
Now this sounds easy, and it is, but for some reason I had a really hard time finding it. The confusion lied in that WordPress names all pages and posts with a “Page ID” number, which is a unique number in the WordPress SQL database, like a primary key. But just because the name says “Page ID”, that doesn’t mean WordPress thinks of pages and posts in the same way. According to the WordPress Codex, when querying a post, you must use “is_single”. Here’s the code below:
Where the number (in this case 1454) is the page ID of the post. NOTE: is_page and is_post do not work for blog post IDs.
thing you wanted to show if that post
thing you wanted to show otherwise
When I was searching for a solution, other people were using it to show or hide excerpts. I was using it to show or hide a specific block of code I was using like a boilerplate at the end of each post in the client’s theme. You can use it to show or hide whatever you like, but let me know in the comments.