问题
Can someone guide me by telling me how I can customize/change Text label in Wordpress - I recently installed WooCommerce on my wordpress, and need to change the label "Product Short Description" on the "Add Product" page to something else. Is there a way to getting this done? Please see this image for reference:
回答1:
To answer to your question: YES there is a working filter hook that can translate text by the internationalization functions (
__()
,_e()
, etc.)
Here is this code:
add_filter( 'gettext', 'theme_domain_change_excerpt_label', 10, 2 );
function theme_domain_change_excerpt_label( $translation, $original )
{
if ( 'Product Short Description' == $original ) {
return 'My Product label';
}
return $translation;
}
This code goes in function.php file of your active child theme (or theme) or also in any plugin file.
The code is tested and fully functional.
References:
- gettext
- Change The Title Of a Meta Box
回答2:
Borrowing from here
The basic premise is that you remove the existing metabox and then add it back with a new title, but the same callback, which (as it happens) is similar to what WooCommerce did with the usual "excerpt" metabox. :
remove_meta_box( 'METABOX_ID', 'POST_TYPE', 'normal' );
add_meta_box('METABOX_ID', __('META BOX TITLE'), 'METABOX_CALLBACK', 'POST_TYPE', 'normal', 'high');
So in this case you'd want to do the following:
add_action( 'add_meta_boxes', 'so_39797888_rename_meta_boxes', 40 );
function so_39797888_rename_meta_boxes(){
remove_meta_box( 'postexcerpt', 'product', 'normal' );
add_meta_box( 'postexcerpt', __( 'This metabox is awesome', 'your-plugin' ), 'WC_Meta_Box_Product_Short_Description::output', 'product', 'normal' );
}
You need to be on a priority of 40 so that your function will come after WooCommerce has added it's metabox.
来源:https://stackoverflow.com/questions/39797888/customizing-woocommerce-short-description-metabox-title