I tried to change the $button_labels
of a WP_Customize_Image_Control()
by modifying its source , change the instances of the button_labels
and rename it.
class WP_Label_Image_Control extends WP_Customize_Upload_Control {
public $type = 'image';
public $mime_type = 'image';
/**
* Constructor.
*
* @since 3.4.0
* @uses WP_Customize_Upload_Control::__construct()
*
* @param WP_Customize_Manager $manager
* @param string $id
* @param array $args
*/
public function __construct( $manager, $id, $args = array() ) {
parent::__construct( $manager, $id, $args );
$this->button_labels = array(
'select' => __( 'NEW Select Image' ),
'change' => __( 'NEW Change Image' ),
'remove' => __( 'NEW Remove' ),
'default' => __( 'NEW Default' ),
'placeholder' => __( 'NEW No image selected' ),
'frame_title' => __( 'NEW Select Image' ),
'frame_button' => __( 'NEW Choose Image' ),
);
}
// More code here...
}
And later use it like this but still, no button label have changed.
$wp_customize->add_control(
new WP_Label_Image_Control(
$wp_customize,
'logo',
array(
'label' => __( 'Label', 'theme-slug' ),
'description' => 'Description here..',
'section' => 'section_id',
'settings' => 'setting_id',
)
)
);
I found that when you set the $type
to a different type like 'upload' or 'media' , the button labels will change according to the button_labels
set of WP_Customize_Media_Control()
. But when you set it to 'image'
, the labels will change according to the button_labels
of WP_Customize_Image_Control()
.
You should avoid editing the source.
As a workaround that may provide better control for you in the future (say you want to change the button label to different things in different circumstances...) you could consider javascript.
<script type="text/javascript">
document.getElementById('CSSID').innerHTML = 'NEW LABEL';
</script>
You can get the script into your footer using a simple function in your functions.php:
add_action('wp_footer', new_button_labels)
function new_button_labels() {
// the script above
}
Later on, if you wanted to use different text for different pages/parts of pages, you could add additional javascript with different CSS selectors to target buttons in different enviorns.
More info here: http://www.tizag.com/javascriptT/javascript-innerHTML.php
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.