- This topic has 6 replies, 2 voices, and was last updated 4 years, 11 months ago by Andrew Misplon.
Tagged: post date selective removal
- AuthorPosts
- October 24, 2019 at 3:30 pm #13395
jfcyrParticipantI’d like to be able to remove post dates on posts of a given category and have the date show on all other posts.
Let me explain.
We have a list of shows we are going to attend. Here for example: https://reflexphotonics.com/ieee-avfop/
On the post page, the date of these posts is the date of creation which bears no relation to the date of the show itself.
I found that confusing, so I removed the date from the posts (appearance>customize>theme settings…).
The problem now is that all other posts (news, announcements…) have no date..
All my show post have a category and a sub-category appended to them (tradeshow-2019; q3-q4) in order to show on this page: https://reflexphotonics.com/company/tradeshow_events/
Is there a way to do have the date show selectively on post pages ?October 24, 2019 at 4:06 pm #13397
Andrew MisplonKeymasterHi JF
Yes, we can do this. I’ll come back to you with a solution.
October 24, 2019 at 6:18 pm #13402
Andrew MisplonKeymasterI’ve added the function here. You can paste the function into the plugin Code Snippets as a new snippet. If you do so, select the option to run the snippet on the site front-end then save and activate. Alternatively, the function can be inserted into a child theme functions.php file. The only line that needs to be changed is:
if ( ! in_category( '1' ) ) {
1
needs to be changed to the ID of the category to exclude the date from. Go to Posts > Categories, edit the category in question and check the URL to locate the category ID.You’ll also need to re-enable the theme setting to display the post date.
October 24, 2019 at 7:02 pm #13403
jfcyrParticipantBrilliant !
One last thing… how do have this work on more that one category concurrently (“tradeshow-2019” and “tradeshow-2020”) for example.
The line reads like this:
if ( ! in_category( ‘492’ ) ) {492 is the category ID for “tradeshow-2019”
642 is the category ID for “tradeshow-2020”October 24, 2019 at 7:48 pm #13404
Andrew MisplonKeymasterOctober 24, 2019 at 8:05 pm #13405
jfcyrParticipantResolved !
Thanks again for the prompt response and help.October 24, 2019 at 8:09 pm #13406
Andrew MisplonKeymasterFor sure, glad to hear that helped 🙂
- AuthorPosts
You must be logged in to reply to this topic.