Is it possible to translate custom post type metaboxes (label not values of metaboxes fields) with localization? Or do I have to use some plugin like WPML? Thank you in advance. I have read this Custom metabox translation but I tried with Codestyling Localization and it didn't work so I am not sure if it is possible to translate those labels.


I pass the array of metaboxes to the constructor:

    'id' => 'rti-meta-box-1',
    'title' => __('Title Options','rti'),
    'pages' => array('post', 'page', 'courses'),
    'context' => 'advanced',
    'priority' => 'default',
    'function_callback' => 'show',
    'fields' => array(
            'name' => __('Show title?','rti'),
            'id' => $prefix . 'title_meta',
            'type' => 'checkbox',
            'std' => 1
            'name' => __('Show breadcrumbs?','rti'),
            'id' => $prefix . 'breadcrumb_meta',
            'type' => 'checkbox',
            'std' => 1

Then in the constructor function add is hooked to admin_menu where add_metabox is called. Function add looks like this:

function __construct($meta_box) {
    $this->_meta_box = $meta_box;       

    add_action('admin_menu', array(&$this, 'add')); 
    add_action('save_post',  array(&$this, 'save'));

/// Add meta box for multiple post types
function add() {
    foreach ($this->_meta_box['pages'] as $page) {
        add_meta_box($this->_meta_box['id'], $this->_meta_box['title'], array(&$this, $this->_meta_box['function_callback']), $page, $this->_meta_box['context'], $this->_meta_box['priority']);

And when I translate for example Title Options it appears the same.

  • By didn't work did you mean that you added the translated strings but they didn't appear translated? How does your add_metabox code look? – czerspalace Jun 24 '15 at 22:13
  • I think you're defining that array (by the way, where are you defining it?) before loading the text domain. – Eduardo Escobar Nov 26 '19 at 21:16

I have found what is the problem. It isn't enough to localize just the labels e.g. ('Label','text_domain'). But also the variable itself - my code should be like this:

add_meta_box($this->_meta_box['id'], ($this->_meta_box['title'],'text_domain'), array(&$this, $this->_meta_box['function_callback']), $page, $this->_meta_box['context'], $this->_meta_box['priority']);

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.