Change The Titles Of Custom Meta Boxes
-
I’m trying to create a function (without the use of JS) to change the title of Custom Meta Boxes.
Currently I have the following code which changes the titles of Core WordPress Meta Boxes (such as author etc.):
//hook to the 'add_meta_boxes' action add_action('add_meta_boxes', 'change_meta_box_titles'); function change_meta_box_titles() { global $wp_meta_boxes; // array of defined meta boxes // cycle through the array, change the titles you want $wp_meta_boxes['post']['normal']['core']['authordiv']['title']= 'Team Member'; }
However it doesn’t appear that custom meta boxes can be called the same way. They don’t show up when you use the following snippet inside your function to view the $wp_meta_boxes array:
echo '<pre>'; print_r($wp_meta_boxes); echo '</pre>'; wp_die('');
Anyone have any suggestions on how to change the titles of custom meta boxes?
-
If I call print_r($wp_meta_boxes); from within my metabox generating class it shows the metaboxes I’ve added.
Thanks noponies for the tip. If I try to use the print_r($wp_meta_boxes) code snippet inside my change_meta_box_titles function (shown in first post), it displays the custom post type but not the custom meta box details.
In order to show the custom meta box details I had to place the print_r($wp_meta_boxes) snippet inside my function to create my meta boxes, once posted there it displays custom post type and custom meta box info.
With the print_r($wp_meta_boxes) snippet now inside my create meta boxes function it displays the following (I left out the portions not related to the custom meta box):
[portfolio] => Array ( [side] => Array ( [high] => Array ( [cc_projectinfo_meta] => Array ( [id] => cc_projectinfo_meta [title] => Project Info [callback] => cc_show_projectinfo_meta_box [args] => ) ) )
The above shows that I should be able to use the following code inside my change_meta_box_titles function to change the title of the custom meta box:
$wp_meta_boxes['portfolio']['side']['high']['cc_projectinfo_meta']['title']= 'A New Title';
However, it doesn’t work. The custom meta box title doesn’t change. Yet now if I use the print_r($wp_meta_boxes) snippet inside the change_meta_box_titles function it displays the following:
[portfolio] => Array ( [side] => Array ( [high] => Array ( [cc_projectinfo_meta] => Array ( [title] => New Title ) ) )
I’m not sure why this isn’t working correctly. Did I miss something? Can anyone offer any further insight here?
Anyone know why this might not be working correctly?
You might try the high priority to make sure the code runs after meta box has been added:
add_action('add_meta_boxes', 'change_meta_box_titles', 999);
That did the trick. What a simple fix that I can’t believe I didn’t test, herp derp. 🙂
- The topic ‘Change The Titles Of Custom Meta Boxes’ is closed to new replies.