0

I was able to find information on how to change the edit views text but so far I've come up empty with changing the text of the "empty trash" button. I'd like to change it for my task management CPT to "Empty Archives." Any suggestions on where to look on how to do this or does anyone know themselves?

I'm looking for a function to accomplish this--I obviously don't want to edit WP core files.

Thanks!

2

There's no way to set this text directly. But, the "Empty Trash" text is run through the translation API before display. You can hijack this translation to replace the text with your own string.

get_current_screen() is used to check the post_type of the current admin screen, so you can make sure you're only affecting your "task" type's screens.

add_filter( 'gettext', 'override_empty_trash', 50, 3 );

/**
 * Override the "Empty Trash" string on admin pages for a custom post type
 *
 * @param string $translated_text translation of $text from previous filter calls
 * @param string $text            original text string
 * @param string $domain          translation domain
 *
 * @return string|void
 */
function override_empty_trash( $translated_text, $text, $domain ) {

    // Skip all of these checks if not on an admin screen
    if ( is_admin() ) {

        if ( 'Empty Trash' === $text ) {

            // get_current_screen returns info on the admin screen, including post_type
            $current_screen = get_current_screen();
            if ( 'my-post-type-slug' === $current_screen->post_type ) {
                // Override the translation, but run the replacement through the translation API
                $translated_text = __( 'Empty Archives', 'my-plugin-translation-domain' );
            }

        }

    }

    return $translated_text;

}
  • Thanks Dave! I hadn't thought about using the translation API. There really is a way to do almost anything in WordPress, isn't there? – Justice Is Cheap Mar 1 '15 at 19:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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