Add a control to WordPress Customize Menu - php

is there a way to add a new control to the "Menu" tab on the customize page?
picture to menu
I want a button right over "Menu Locations".
I've already try to use a add_control function like this:
$wp_customize->add_control( new WP_Customize_Control(
$wp_customize,
'test',
array(
'label' => __( 'Test', 'yespizza' ),
'section' => 'nav_menus',
'settings' => 'test_setting',
'priority' => 10,
)
));
I don't know how i can get the right section name for the menu.
regards

Related

Wordpress Customizer values not show in the front page after theme installation

I am working on a wordpress theme and after theme installation, the default values set for customizer are not displayed on the page, but in customizers they appear. If I change something in a field in the customizer and click publish, it is displayed on the web page. Does anyone know why? the code doesn't seem to be a problem.
customizer.php:
<?php
function photonium_customizer_register($wp_customize){
$wp_customize->add_panel('home_panel', array(
'title' => 'Front Page',
'priority' => 1,
'capability' => 'edit_theme_options',
));
$wp_customize->add_section('home_section', array(
'title' => 'Home Section',
'description' => __('Here you can custom the Front Page content. <br/> To not display some fields, leave them empty.'),
'panel' => 'home_panel',
));
$wp_customize->add_setting('main_title', array(
'default' => __('Professional Photographer'),
));
$wp_customize->add_control('main_title', array(
'label' => 'Home Main Title',
'section' => 'home_section',
'priority' => 1,
));
$wp_customize->selective_refresh->add_partial('main_title', array(
'selector' => '.main-title',
));
}
add_action( 'customize_register', 'photonium_customizer_register' );
front-page.php:
<?php if( get_theme_mod( 'main_title') ): ?>
<p class="main-title"><?php echo get_theme_mod('main_title', 'Professional Photographer'); ?></p>
<?php endif; ?>
...

How to create a Call to Action button on a banner using Wordpress Customizer

I'm a WordPress beginner.
This is my first question in Stackoverflow.
I am using the theme (wp bootstrap starter) I want to add an action call button, I have managed to show the button and customize it from the wordpress customizer but I have not been able to with the URL for the button.
I also want that when there is no text in the button, it does not show it to me in the front-end
Can someone help me with this please, I really appreciate it.
This is the code i am using:
functions.php
$wp_customize->add_setting( 'header_banner_button_setting', array(
'default' => __( 'Button' ),
'sanitize_callback' => 'wp_filter_nohtml_kses',
) );
$wp_customize->add_control( new WP_Customize_Control($wp_customize, 'header_banner_button_setting', array(
'label' => __( 'Banner Button', 'wp-bootstrap-starter' ),
'section' => 'header_image',
'settings' => 'header_banner_button_setting',
'type' => 'text'
) ) );
header.php
<button>
<?php
if(get_theme_mod( 'header_banner_button_setting' )){
echo esc_attr( get_theme_mod( 'header_banner_button_setting' ) );
}else{
echo esc_html__('','wp-bootstrap-starter');
}
?>
</button>

Adding subtitles to products in Woocommerce

I'd like to be able to add a subtitle to my products in Woocommerce only on the shop page. I have it set up as a catalog right now, since I'm not actively selling my products yet, so I have disabled the add to cart button and the prices. I would like to be able to say how many colors the product comes in as a subtitle. I have read up on adding meta boxes with Woocommerce, and found this solution and added it to my functions.php, but it doesn't appear to be working on my site (I can't find where to enter the information for the product!)
add_filter( 'cmb_meta_boxes', 'bhww_core_cpt_metaboxes' );
function bhww_core_cpt_metaboxes( $meta_boxes ) {
//global $prefix;
$prefix = '_bhww_'; // Prefix for all fields
// Add metaboxes to the 'Product' CPT
$meta_boxes[] = array(
'id' => 'bhww_woo_tabs_metabox',
'title' => 'Additional Product Information - <strong>Optional</strong>',
'pages' => array( 'product' ), // Which post type to associate with?
'context' => 'normal',
'priority' => 'default',
'show_names' => true,
'fields' => array(
array(
'name' => __( 'Colors', 'cmb' ),
'desc' => __( 'Anything you enter here will be displayed on the Colors tab.', 'cmb' ),
'id' => $prefix . 'ingredients_wysiwyg',
'type' => 'wysiwyg',
'options' => array( 'textarea_rows' => 5, ),
),
),
);
return $meta_boxes;
}

How to add custom fields to customize menu in Wordpress

I want to add some custom menu points to the customize menu. So the user is able to edit the page much easier.
In your theme go to the function.php
and Code like this
function self_customizer_section($wp_customize) {
$wp_customize->add_section( 'section_name' , array(
'title' => __( 'Self Logo', 'my_theme' ),
'description' => 'theme general options',
));
/* LOGO */
$wp_customize->add_setting( 'self_logo', array(
'default' => get_template_directory_uri().'/images/mytheme.png'
));
$wp_customize->add_control( new WP_Customize_Image_Control( $wp_customize, 'self_logo', array(
'label' => __( 'Main Logo', 'my_theme' ),
'section' => 'section_name',
'settings' => 'self_logo',
)));
}
add_action('customize_register', 'self_customizer_section');
For more detail you can follow the below link he made the awesome tutorial on that question
See in continuation.
here is the link
Wordpress Theme Customization API Tutorial

Using WordPress' Theme Customizer to select page templates that update layout in the preview

I wasn't sure where to post this question..
I recently discovered WordPress' "Theme Customizer" and am using it to make the pages easier to update for clients. Rather than the standard way of editing each individual page, clicking update, and then visiting the page to see the changes, I like how the Theme Customizer automatically previews your changes on the right side.
I am trying to get an understanding of how far I can go with the Theme Customizer before I go all out on this...
I've created a "Home Page" setting/section/control pictured here:
And here is the code for this:
function prowordpress_customize_register( $wp_customize ) {
// Settings, Sections, and Controls are defined here
// HOME PAGE
$wp_customize->add_setting( 'home_page_text' , array(
'default' => 'This is the home page text',
'type' => 'option',
'transport' => 'refresh',
));
$wp_customize->add_section( 'prowordpress_content_customizations' , array(
'title' => __('Home Page', 'prowordpress'),
'description' => __('Modify the Home Page', 'prowordpress'),
'priority' => 30,
));
$wp_customize->add_control( 'home_page_text_control', array(
'label' => __( 'Home Page Text', 'prowordpress' ),
'section' => 'prowordpress_content_customizations',
'settings' => 'home_page_text',
'type' => 'textarea',
));
$wp_customize->add_setting( 'home_page_template_select' , array(
'default' => 'test',
'type' => 'option',
'transport' => 'refresh',
));
$wp_customize->add_control(
new WP_Customize_Control(
$wp_customize,
'home_page_template_select',
array(
'label' => __( 'Home page template:', 'blankwptheme' ),
'section' => 'prowordpress_content_customizations',
'settings' => 'home_page_template_select',
'type' => 'select',
'choices' => array(
'template_one' => __( 'Template Layout 1' ),
'template_two' => __( 'Template Layout 2' )
)
)
)
);
}
add_action( 'customize_register', 'prowordpress_customize_register' );
You can see in the screenshot I've added a select menu for "Home page template"...
Is it possible I could set it up where the client can choose an existing "page template" from this select menu and then have the page preview/layout on the right hand side automatically inherit the page template settings and adjust the layout in real-time?
Again, I'm just trying to understand if this is feasible, and if anyone has tried something similar before. I realize this may require some AJAX or something along those lines.
Thanks for the help!
Yes, You can. I have done this type of layout selection in my own theme.
in your php file you need to do something like this -
<?php if ( get_option( 'home_page_template_select' ) === 'template_one' ) {
get_template_part( 'layouts/template-one' ); ?>
I hope that helps.

Categories