To add a new title and its description inside a section in the WordPress Customizer, you’ll need to add a custom_control
for this purpose. You can create a custom control class for displaying the title and description, and then add an instance of this control to your section.
Here’s how you can do it:
- Create a Custom Control Class:
First, create a custom control class to handle the display of your title and description.
if ( class_exists( 'WP_Customize_Control' ) ) {
class My_Custom_Title_Control extends WP_Customize_Control {
public $type="custom_title";
public $description = '';
public function render_content() {
?>
<h2><?php echo esc_html( $this->label ); ?></h2>
<?php if ( ! empty( $this->description ) ) : ?>
<p><?php echo esc_html( $this->description ); ?></p>
<?php endif; ?>
<?php
}
}
}
- Add the Custom Control to Your Section:
In your theme’sfunctions.php
file or wherever you are adding your customizer settings, add the following code to include the new control:
function mytheme_customize_register( $wp_customize ) {
// Assuming your section is already created and named 'my_custom_section'
$wp_customize->add_section( 'my_custom_section', array(
'title' => __( 'My Custom Section', 'mytheme' ),
'priority' => 30,
));
// Add the custom title control
$wp_customize->add_setting( 'my_custom_title_setting', array(
'sanitize_callback' => 'wp_kses_post', // Sanitize the content if needed
));
$wp_customize->add_control( new My_Custom_Title_Control( $wp_customize, 'my_custom_title', array(
'label' => __( 'General Settings', 'mytheme' ),
'description' => __( 'This is a small description of the General Settings section.', 'mytheme' ),
'section' => 'my_custom_section',
'settings' => 'my_custom_title_setting',
'priority' => 1,
)));
}
add_action( 'customize_register', 'mytheme_customize_register' );