I'm using the Kirki plugin to add fields and sections in the WordPress customizer. So far, I can get a field to be added to the customizer, but I'm confused on how to return that data back into my theme. I'm kinda tired so I might be missing something. This is what I have so far:
Kirki::add_config('theme_config_id', array(
'capability' => 'edit_theme_options',
'option_type' => 'theme_mod',
));
Kirki::add_section('footer_section', array(
'title' => __('Footer'),
'description' => __('Add custom footer here'),
'panel' => '', // Not typically needed.
'priority' => 160,
'capability' => 'edit_theme_options',
'theme_supports' => '', // Rarely needed.
));
Kirki::add_field('theme_config_id', [
'type' => 'editor',
'settings' => 'my_setting',
'label' => esc_html__('Footer Content', 'kirki'),
'description' => esc_html__('This content will show in the footer.', 'kirki'),
'section' => 'footer_section',
'default' => '',
]);
I was reading on trying to the values out from here using this:
$value = Kirki::get_option( $config_id, $option_id );
But I'm not sure where (or what) the $config_id or $option_id would be?
I have a feeling that I'm missing something and I've read through the docs and I feel that I'm not getting it.
This is the correct code
$value = Kirki::get_option( 'config_id', 'option_id' );
so in your case,
$value = Kirki::get_option( 'theme_custom', 'footer_content' );
After digging through the internet a little bit, I was able to read through some more documentation as well as some other examples and I was able to figure out what I was doing wrong. Overall, I was close, but I ended up cleaning it up and just using the WordPress get_theme_mod() outright in my template file (in this case it was the footer.php file).
Here's what I ended up with:
Kirki::add_config('theme_custom', array(
'capability' => 'edit_theme_options',
'option_type' => 'theme_mod'
));
Kirki::add_section('footer_section', array(
'title' => __('Footer'),
'description' => __('Add custom footer here'),
'panel' => '', // Not typically needed.
'priority' => 160,
'capability' => 'edit_theme_options',
'theme_supports' => '', // Rarely needed.
));
Kirki::add_field('theme_custom', array(
'type' => 'editor',
'settings' => 'footer_content',
'label' => esc_html__('Footer Content', 'kirki'),
'description' => esc_html__('This content will show in the footer.', 'kirki'),
'section' => 'footer_section',
'default' => '',
'priority' => 10
));
and in my footer.php file, I added this:
<?php $value = get_theme_mod('footer_content', ''); ?>
<?php echo($value); ?>
Granted, this is a super basic way of implementing this. I'm going to try and figure out how to get it to refresh the customizer preview before you publish it. But for now, this seems to be working.
Related
I'm trying to update my theme via Updates API in WordPress and can't get it to work.
Here's the transient value:
(object) array(
'last_checked' => 1675756430,
'checked' => array(
'chipmunk-lite' => '1.0',
'chipmunk-theme' => '1.17.1',
),
'response' => array(
'chipmunk-theme' => array(
'theme' => 'chipmunk-theme',
'new_version' => '1.18.0',
'url' => 'https://chipmunktheme.com',
'package' => 'https://app.lemonsqueezy.com/download/unique_id',
'requires' => NULL,
'requires_php' => NULL,
'sections' => array(
'description' => '<p>Makes it ridiculously easy to make a content curation website for marketing, authority or just for fun. No coding skills required.</p>',
'changelog' => '1.18.0',
),
),
),
'no_update' => array(),
'translations' => array(),
)
The update alert does not show up. Is there anything wrong with it?
I'm following this guide: https://make.wordpress.org/core/2020/07/30/recommended-usage-of-the-updates-api-to-support-the-auto-updates-ui-for-plugins-and-themes-in-wordpress-5-5/
i'm trying to add a tab to my wordpress customizer.
i use the next code:
add_action('customize_register','theme_costumizer_register');
function theme_costumizer_register($wp_customize){
$wp_customize->add_section('facebook_new_section', array(
'title' => 'Social Media',
'priority' => 10
));
$wp_customize->add_settings('facebook',
array(
'default' => 'http://facebook.com/ahiad'
));
$wp_customize->add_control(new WP_Customize_Control($wp_customize,'txtFacebookAddress',
array(
'label' => 'Facebook Link',
'section' => 'facebook_new_section',
'type' => 'text'
)));
}
the problem is every time i run this piece of code in my website, i get an error 500, could not spot the problem here...
You are using $wp_customize->settings which is not not exists, Please use $wp_customize->setting.
Please try below code :
add_action('customize_register','theme_costumizer_register');
function theme_costumizer_register($wp_customize){
$wp_customize->add_section('facebook_new_section', array(
'title' => 'Social Media',
'priority' => 10
));
$wp_customize->add_setting('facebook',
array(
'type' => 'theme_mod', // or 'option'
'capability' => 'edit_theme_options',
'theme_supports' => '', // Rarely needed.
'default' => 'http://facebook.com/ahiad',
'transport' => 'refresh', // or postMessage
'sanitize_callback' => '',
'sanitize_js_callback' => '',
));
$wp_customize->add_control('facebook',
array(
'label' => 'Facebook Link',
'section' => 'facebook_new_section',
'type' => 'text'
));
}
I hope it will helps you. Thanks
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 have just registered a new Custom Taxonomy in Wordpress (as per the docs). Here is a copy of the code in functions.php for reference:
function people_init() {
// create a new taxonomy
register_taxonomy(
'people',
'post',
array(
'label' => __( 'People' ),
'rewrite' => array( 'slug' => 'person' ),
'capabilities' => array(
'assign_terms' => 'edit_guides',
'edit_terms' => 'publish_guides'
)
)
);
}
add_action( 'init', 'people_init' );
As you can see in the image below, the Taxonomy appears within left-hand navigation but when my (admin) user clicks on the option I am displayed with an You are not allowed to edit this item. error:
Can anyone suggest why this may be?
Almost as soon as I posted this I realised it is the capabilities array. Removing this, so that it reverts to the default allows access as intended.
After further investigation I found that the following was the best settings to get this functioning correctly:
'capabilities' => array(
'manage__terms' => 'edit_posts',
'edit_terms' => 'manage_categories',
'delete_terms' => 'manage_categories',
'assign_terms' => 'edit_posts'
)
Im having a bit of a problem with my theme, i have added the following code to page.tpl.php to display the main menu links, but nothing is showing.
$main = menu_navigation_links('main-menu', '1');
echo theme('links__system_main_menu', array(
'links' => $main,
'attributes' => array(
'id' => 'nav'
),
));
Could someone let me know where im going wrong.
Cheers,
Try with this
print theme('links__system_main_menu', array(
'links' => $main_menu,
'attributes' => array(
'id' => 'main-menu',
'class' => array('links', 'inline', 'clearfix'),
),
'heading' => array(
'text' => t('Main menu'),
'level' => 'h2',
'class' => array('element-invisible'),
),
));
Otherwise you can always place the menu throught blocks and regions.
This is because you are asking for a depth (=1) where you do not have any links.
Try $main = menu_navigation_links('main-menu', '0');
Drupal 7 API about menu_navigation_links