I created a section for my template in the customization section using the select controller so that the user can choose one of several texts to display on the page.
The code in the customization section works fine, but I want to click on each option to show the text I set for it, and hide the rest.
In summary: If the user selects teb2, the .txt_one class will be displayed and the rest of the classes will be display: none.
And for the rest of the selection controller options, it should be the same.
I have put a code in the functions.php file to create customization with the selection controller:
function edite_add_select($wp_customize){
//add section
$wp_customize->add_section( 'edite_select_section', array(
'title' => 'Select text',
'priority' => 10,
'description' => 'Select the text you want'
));
//add setting
$wp_customize->add_setting( 'edite_select', array(
'default' => 'teb1',
));
//add control
$wp_customize->add_control( 'edite_select_control', array(
'label' => 'Change the default text',
'type' => 'select',
'section' => 'edite_select_section',
'settings' => 'edite_select',
'choices' => array(
'teb1' => 'default',
'teb2' => 'The first text',
'teb3' => 'The second text',
)
));
}
add_action( 'customize_register', 'edite_add_select' );
The code I put on the page in question:
<div>
<h2 id="text_title">Display text</h2>
<p class="txt_default">text default</p>
<p class="txt_one">text one</p>
<p class="txt_two">text two</p>
</div>
source https://stackoverflow.com/questions/76547375/create-a-conditional-command-to-customize-the-selection
No comments:
Post a Comment