I am trying to add an extra setting in the Wordpress customizer. Can you add extra settings in the site title & tagline section or do you have to create your own section? This is the code I have so far in my functions.php file:
function mytheme_customize_register( $wp_customize )
{
$wp_customize->add_control(
new WP_Customize_Control(
$wp_customize,
'your_setting_id',
array(
'label' => __( 'Your Label Name', 'theme_name' ),
'section' => 'title_tagline',
'settings' => 'your_setting_id',
'type' => 'text'
)
)
);
}
add_action( 'customize_register', 'mytheme_customize_register' );
If I try to go to the customize theme page in the admin area though I get the following error:
Fatal error: Call to a member function check_capabilities() on a non-object in C:\xampp\htdocs\one-gas\wp-includes\class-wp-customize-control.php on line 161
Yes, you can add to the title and tagline section. Try using this code:
$wp_customize->add_control(
new WP_Customize_Control(
$wp_customize,
'your_setting_id',
array(
'label' => __( 'Your Label Name', 'theme_name' ),
'section' => 'title_tagline',
'settings' => 'your_setting_id',
'type' => 'text'
)
)
)
);
Read more about the Theme Customization API at the WordPress Codex.
I fixed it in the end it's because I had to define a setting first so this is the working code:
function mytheme_customize_register( $wp_customize )
{
$wp_customize->add_setting('subtagline', array(
'default' => 0,
'type' => 'option'
));
$wp_customize->add_control(
new WP_Customize_Control(
$wp_customize,
'subtagline',
array(
'label' => __( 'Sub Tagline', 'One Gas' ),
'section' => 'title_tagline',
'settings' => 'subtagline',
'type' => 'text'
)
)
);
}
add_action( 'customize_register', 'mytheme_customize_register' );
Related
What is the customizer section name? I want to add a field option under customizer woocommerce section. Or how will I add a field under woocommerce option? Can someone help me with that?
$wp_customize->add_section( 'woocommerce_secction_name' , array(
'title' => __( 'My Section Name', 'starter' ),
'priority' => 30
) );
$wp_customize->add_setting( 'starter_new_setting_name' , array(
'default' => '#000000',
'transport' => 'refresh',
) );
$wp_customize->add_control( new WP_Customize_Color_Control( $wp_customize, 'link_color', array(
'label' => __( 'Header Color', 'starter' ),
'section' => 'woocommerce_secction_name',
'settings' => 'starter_new_setting_name',
) ) );
// Add section to WooCommerce Panel
$wp_customize->add_section( 'SECTION_NAME',
array(
'title' => __( 'SECTION TITLE'),
'panel' => 'woocommerce',
'capability' => '',
'priority' => 500,
)
);
The important part is the panel name as you can see selecting woocommerce it will add to the woocomerce panel
Hi Im practically a newbie and would like to kindly ask how can I display skill1_logo,skill1_title,skill1_description on a page that I want. I was trying to do a 1 page website using wordpress to practice my wordpress.
function theme_skills_customizer($wp_customize){
//adding section in wordpress customizer
$wp_customize->add_section('skills_settings_section', array(
'title' => 'Skills Section'
));
$wp_customize->add_setting('skill1_logo');
$wp_customize->add_setting('skill1_title');
$wp_customize->add_setting('skill1_description');
$wp_customize->add_control( new WP_Customize_Image_Control( $wp_customize, 'skill1_logo', array(
'label' => __( 'Skill 1 Logo', 'themeslug' ),
'width' => 400,
'height' => 400,
'flex-width' => true,
'flex-height' => true,
'section' => 'skills_settings_section',
'settings' => 'skill1_logo',
)));
$wp_customize->add_control( 'skill1_title', array(
'label' => __( 'Skill 1 Title' ),
'section' => 'skills_settings_section', // Add a default or your own section
'type' => 'text',
));
$wp_customize->add_control( 'skill1_description', array(
'label' => __( 'Skill 1 Description' ),
'section' => 'skills_settings_section', // Add a default or your own section
'type' => 'textarea',
));
}
add_action( 'customize_register', 'theme_skills_customizer' );
You can use get_theme_mod function to echo those settings.
e.g.
$s_title = get_theme_mod('skill1_title');
I'm trying to retrieve some customizer settings that I initiated.
function notop_customize_register( $wp_customize ) {
$wp_customize->add_section( 'header_images', array(
'title' => 'Header Images',
'priority' => 2,
'description' => "Add images with links to be redirected to when the images are clicked",
) );
// Add color scheme setting and control.
$wp_customize->add_setting( 'header_image_1_setting', array(
'capability' => 'edit_theme_options',
'type' => 'option',
) );
$wp_customize->add_control(new WP_Customize_Upload_Control($wp_customize,'header_image_1_control', array(
'label' => __( 'Import Image', 'notop' ),
'section' => 'header_images',
'settings' => 'header_image_1_setting',
) ) );
}
add_action( 'customize_register', 'notop_customize_register' );
How do I get the url of header_image_1?
I thought it might be get_theme_mod('header_image_1_setting'); but that hasn't worked so far. Also, I'm not sure if I'm actually supposed to call the customize_register file in my index somewhere or if it's okay the way it is.
cale_b's comment is the answer.
get_option('header_image_1_setting')
=> http://...
I'm trying to implement this class: A WordPress Settings Class for Options Pages
What I tried:
function add_wp_page(){
require_once( TEMPLATEPATH."/folder_admin/wm-settings.php" );
// A top level page
$my_top_page = create_settings_page(
'my_top_level_page',
__( 'My Top Level Page' ),
array(
'parent' => false,
'title' => __( 'Top Level Menu' ),
'icon_url' => 'dashicons-admin-generic',
'position' => '63.3'
),
array(
'my_standard_section' => array(
'title' => __( 'Standard' ),
'description' => __( 'My section description.' ),
'fields' => array(
'my_input' => array(
'label' => __( 'Input example' )
),
'my_checkbox' => array(
'type' => 'checkbox',
'label' => __( 'Checkbox example' )
),
'my_textarea' => array(
'type' => 'textarea',
'label' => __( 'Textarea example' )
)
)
)
),
array(
'tabs' => true,
'submit' => __( 'My Submit' ),
'reset' => __( 'My reset' ),
'description' => __( 'My page description.' ),
'updated' => __( 'My success message !')
)
);
// And a sub-page
$my_sub_page = create_settings_page(
'my_sub_page',
__( 'My Sub Page' ),
array(
'parent' => 'my_top_level_page',
'title' => __( 'Sub Level Menu' )
)
);
}
add_action( 'admin_init', 'add_wp_page' );
The TEMPLATEPATH is it ok. If I echo something in wp-settings.php it will print it.
The rest of the code it is from that website. It is from an example.
The menu doesn't show.
Am I missing something?
Thanks
The settings need to be registered before 'admin_init'.
Replace the last line with add_action( 'init', 'add_wp_page' );.
Also, avoid wrapping the require_once in an action or you won't be able to access get_setting() outside your hook.
Oh, and the position can be a string. And it is actually recommended to use a decimal number to prevent possible conflicts for these menu positions with other plugins or themes.
Please set a 'position' => '63.3' to integer.
or use positions of core menu:
2 Dashboard
4 Separator
5 Posts
10 Media
15 Links
20 Pages
25 Comments
59 Separator
60 Appearance
65 Plugins
70 Users
75 Tools
80 Settings
99 Separator
The position in the menu order this menu should appear.
Hope it solves your problems :)
i've got a problem with theme customizer. My code is:
function candyfloss_theme_customizer( $wp_customize ) {
class Heading extends WP_Customize_Control {
public $type = 'heading';
public function render_content() {
?>
<label>
<span class="customize-control-title" style="border-bottom: 1px dashed #666;"><strong><?php echo esc_html( $this->label ); ?></strong></span>
</label>
<?php
}
}
$wp_customize->add_setting('products_heading', array(
'default',
) );
$wp_customize->add_control(new Heading ($wp_customize, 'products_heading', array(
'label' => __('Home - products section'),
'type' => 'heading',
'section' => 'home',
) ) );
$wp_customize->add_setting('candyfloss_product_first', array(
'deafault',
) );
$wp_customize->add_control('candyfloss_product_first', array(
'label' => __('First product page'),
'type' => 'dropdown-pages',
'section' => 'home',
) );
$wp_customize->add_setting('candyfloss_product_second', array(
'deafault',
) );
$wp_customize->add_control('candyfloss_product_second', array(
'label' => __('Second product page'),
'type' => 'dropdown-pages',
'section' => 'home',
) );
$wp_customize->add_setting('candyfloss_product_third', array(
'deafault',
) );
$wp_customize->add_control('candyfloss_product_third', array(
'label' => __('Third product page'),
'type' => 'dropdown-pages',
'section' => 'home',
) );
};
add_action( 'customize_register', 'candyfloss_theme_customizer', 11 );
And the problem is in order of this. At admin panel view is
second option,
first option,
heading,
third option,
Can anyone know, what I'm doing wrong? Could You help me? I'll be thankful
I found the answer. Wordpress gives a random priority to controls. To solve it we just need to add priority number to each control.
eg.:
$wp_customize->add_control(new Heading ($wp_customize, 'products_heading', array(
'label' => __('Home - products section'),
'type' => 'heading',
'section' => 'home',
'priority' => 2,
) ) );