0

I've found tweaking some of the text in WordPress to be pretty easy by adding in the following function (in lieu of using a separate plugin):

add_filter( 'gettext', 'of_site_translations', 9999, 2 );
function of_site_translations( $translation, $text ) {
if ( $text == 'Posts' )
        return 'News Posts';
return $translation;
}

The issue I'm running into is (in my above example) while it will change Posts to News Posts in the WP Sidebar - areas that are dynamically created based on the post type labels; when you click on Posts from the sidebar and it leads you to a page that says Posts. Is there a way to override post type labels using this method? If so, any pointers that could push me along a bit? Really appreciate it, thanks!

0

You could just rename the labels associated with that post type.

class News_Post_Type {
    const POST_TYPE = 'post';

    public static function init() {
        $post_obj = get_post_type_object('post');
        $post_obj->labels->name = __('News Post', 'textdomain');
        $post_obj->labels->singular_name = __('News Post', 'textdomain');
        // You can continue to rename all the label properties, this is just an example
    }
}

add_action( 'init', array( 'News_Post_Type', 'init' ) );
2
  • Wow! I had no idea this was possible. Was this something you also stumbled upon, or is there something in the codex I maybe missed about this? Really appreciate it!
    – Zach
    Dec 22 '11 at 13:23
  • Had to do the same thing at work and it was suggestion from a co-worker. Dec 22 '11 at 21:41
0

This depends on the theme you are using and how well it is using WordPress' string translations. Any text wrapped in translation strings can be modified using the gettext filter. Check this link for more information on translation strings -> http://codex.wordpress.org/I18n_for_WordPress_Developers

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.