• Hi,

    How to remove ‘Dates’ seen on the posts as well as under related posts?

    • This topic was modified 2 years, 2 months ago by Jan Dembowski. Reason: Moved to Fixing WordPress, this is not an Developing with WordPress topic
Viewing 6 replies - 1 through 6 (of 6 total)
  • It depends on your theme, and your template, your configuration.
    You would need to provide URL to your site, or more info.

    Hi @shahekta43,

    There are three ways to achieve this:

    1. Using the admin dashboard: This approach does not require coding and is a hacky way to remove dates.
    Go to the admin dashboard > Settings > General and on the date format section, select Custom and delete whatever is there and click on Save Changes.
    The drawback is, this will affect all the places that displays the date.

    2. Using Custom CSS – For this, you need to know the class name of the element that is displaying the date. Like @corrinarusso mentioned, we would require the site URL to figure out the class. Once we have the class, we can go to admin dashboard > Appearance > Customize > Additional CSS and set the class’s display property to ‘none’.

    3. This approach requires coding and is the most reliable out of the three. If you are comfortable with coding, you can add the below code in the functions.php file of your child theme.

    function remove_date_from_post( $the_date, $format, $post ) {
    	if ( is_admin() ) {
    		return $the_date;
    	}
    
    	if ( 'post' !== $post->post_type ) {
    		return $the_date;
    	}
    	return '';
    }
    
    function remove_time_from_post( $the_time, $format, $post ) {
    	if ( is_admin() ) {
    		return $the_time;
    	}
    
    	if ( 'post' !== $post->post_type ) {
    		return $the_time;
    	}
    	return '';
    }
    
    add_filter( 'get_the_date', 'remove_date_from_post', 10, 3 );
    add_filter( 'get_the_time', 'remove_time_from_post', 10, 3 );

    This will only remove the date from the post post type.

    Thread Starter shahekta43

    (@shahekta43)

    Thanks Kaavya. This was helpful. Can you also guide me on how to remove the author name as well?

    Hi @shahekta43,

    You’re welcome. Removing author name is a bit tricky. If possible, can you share the link to your website so that I can take a look?

    Thread Starter shahekta43

    (@shahekta43)

    Hi @kaavya

    https://advancehealthtips.com/

    • This reply was modified 2 years, 2 months ago by shahekta43.

    Hi @shahekta43,

    Looking at your website, using the function approach (#3) from my first reply will only remove the date and the author name. The calendar and author icons will remain visible because they are being rendered before our function runs. To remove the data (date and author name) as well as the icons from post post type, it would be better to use custom CSS.

    Add the following in admin dashboard > Appearance > Customize > Additional CSS:

    .single-post .entry-meta .byline, .single-post .entry-meta .posted-on {
        display: none
    }

    Please note that this custom CSS will work as long as you continue using the same theme. If you change the theme, the custom CSS will have to be modified based on the class name of the author name and date elements.

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘How to remove ‘Dates’ from posts?’ is closed to new replies.