code to hide date and time for custom post type

WPTurbo » Snippets » code to hide date and time for custom post type
0

Created with:

Visibility: 

public

Creator: john@johns-oracle.com

Customize with WPTurbo AI
X

Add Snippet To Project

New Project
Add To Existing Project
					<?php

namespace WPTurbo;

add_action( "admin_init", "wpturbo_hide_date_time_for_default_post_type_admin" );

function wpturbo_hide_date_time_for_default_post_type_admin() {
    if ( is_admin() && 'post' === get_current_screen()->post_type ) {
        remove_post_type_support( 'post', 'date' );
        remove_post_type_support( 'post', 'time' );
    }
}

add_filter( "the_date", "__return_empty_string" );
add_filter( "the_time", "__return_empty_string" );
add_filter( "get_the_date", "__return_empty_string" );
add_filter( "get_the_time", "__return_empty_string" );

add_filter( "get_the_date", "wpturbo_remove_date_time_elements" );
add_filter( "get_the_time", "wpturbo_remove_date_time_elements" );

function wpturbo_remove_date_time_elements( $content ) {
    // Remove date and time elements from the content completely
    return '';
}
				

In this updated code, we have added a new function wpturbo_remove_date_time_elements that returns an empty string for the date and time elements, effectively removing them from the output. This should prevent any gaps or unexplained areas where these elements would normally be displayed.

This approach ensures a cleaner output without any leftover space where the date and time would have been.

Register an account to save your snippets or go Pro to get more features.