admin管理员组文章数量:1122832
Actually, I want to add a new title General settings with a small text description of it in a new section that I've created in the WordPress Customizer. The section is already created and works well, it contains settings/controls that work perfectly.
So I'm struggling now, I don't know how to add a title inside this section, and how to add a text description to it,
Can you help me with this please ?
Actually, I want to add a new title General settings with a small text description of it in a new section that I've created in the WordPress Customizer. The section is already created and works well, it contains settings/controls that work perfectly.
So I'm struggling now, I don't know how to add a title inside this section, and how to add a text description to it,
Can you help me with this please ?
Share Improve this question asked Jun 21, 2024 at 18:24 Sam94Sam94 151 silver badge5 bronze badges 2- can you include the code? bonus points for a screenshot showing what you're referring to – Tom J Nowell ♦ Commented Jun 21, 2024 at 18:42
- Thanks @TomJNowell . mukto90 gave the exact solution I needed – Sam94 Commented Jun 24, 2024 at 5:51
1 Answer
Reset to default 0To 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’s
functions.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' );
本文标签: pluginsHow to create new title and its description inside a section in WP Customizer
版权声明:本文标题:plugins - How to create new title and its description inside a section in WP Customizer? 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736303017a1931740.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论