WordPress: Remove Date From Posts on Category Page

The first thing you will need in order to remove the date from category pages is the id of the category which you wish to hide the dates on. To get the id click on ‘Categories’ in the admin and then click on the actual category you wish to affect. In the url you will see the id, similar to this:

In this instance, our ID is ’42’. Next you will need to find the file that you need to add the code into. By default WordPress will look in

\wp-content\themes\'your-theme'\

for the file in this order:

  1. category-slug.php (Note: available with Version 2.9)
  2. category-ID.php
  3. category.php
  4. archive.php
  5. index.php

Once you have found the appropriate file modify it like so around line 53 near the h2 tag:

<?php //hide date for category
	$show_date=true;
	$cat_array =  get_the_category($post->ID); 
	//print_r($cat_array);	
	$count = count($cat_array);
        for($i=0 ; $i < $count; $i++){
            $cat_id = $cat_array[$i]->cat_ID;
	    if ($cat_id == 42){
	        $show_date = false;
	    }
        }
if ($show_date) {?>
<span class="date"><?php the_time('d M'); ?></span>
<?php
}
?>

Be sure to replace the number on this line

 if ($cat_id == 42)

with this ID from above.
If you wish to hide the date on individual posts, you can add the same code to ‘single.php’

2 thoughts on “WordPress: Remove Date From Posts on Category Page”

  1. I’m just commenting to let you understand what a awesome experience my friend’s daughter encountered studying yuor web blog. She realized plenty of details, which included how it is like to have an amazing coaching nature to make many people without difficulty grasp several hard to do issues. You truly did more than my expectations. I appreciate you for offering these priceless, healthy, explanatory and unique guidance on your topic to Sandra.

Leave a Reply

Your email address will not be published.