0

I want to hide Status option on publishbox and rename Published on to Date Created for Custom post post_type like you see in red on the below picture.

enter image description here

1 Answer 1

1

Both those strings seem to be located in wp-admin/includes/meta-boxes.php. They don't have any filters attached to them, so they're not meant to be (easily) altered by your code.

However, both those strings are internationalized (ie, run through a translation function) to allow WordPress's interface to be translated into languages other than English. The i18n functions—__() and _e()—both use translate(), which provides a filter, gettext, that you can use to control what is displayed.

Caveats:

  • This may adversely affect the translatability of your plugin.
  • If WordPress ever changes the strings used in these locations, your filter will no longer work.

With that in mind, this code should be a good starting point.

add_filter( 'gettext', 'wpse406946_change_meta_strings', 10, 3 );

/**
 * Change the "Published On:" string and remove the "status: " line from 
 * my CPT's meta box.
 *
 * @param  string $translation The translated string.
 * @param  string $text        The original string.
 * @param  string $domain      The current text domain.
 * @return string              The filtered translated text.
 */
function wpse406946_change_meta_strings( $translation, $text, $domain ) {
    // Checks for the custom post type.
    if ( 'my_post_type' === get_post_type() && 'default' === $domain ) {
        // Unhooks the filter to prevent infinite loops.
        remove_filter( 'gettext', 'wpse406946_change_meta_strings', 10, 3 );
        if ( 'Published on: %s' === $text ) {
            $translation = __( 'Created on: $%s', $domain );
        }
        // The "Status: Published" message is actually 2 parts.
        // This should catch both.
        if ( 'Status:' === $text || 'Published' === $text ) {
            $translation = '';
        }

        // Rehooks the filter.
        add_filter( 'gettext', 'wpse406946_change_meta_strings', 10, 3 );
    }

    return $translation;
}

References

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.