Skip to content

Instantly share code, notes, and snippets.

@humayunahmed8
Created October 12, 2023 06:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save humayunahmed8/d23ed0b8b989e04cd93bed176ca7d169 to your computer and use it in GitHub Desktop.
Save humayunahmed8/d23ed0b8b989e04cd93bed176ca7d169 to your computer and use it in GitHub Desktop.
Create customize option with Kirki and then retrive shortcode
<?php
Kirki::add_config('theme_config_id', array(
'capability' => 'edit_theme_options',
'option_type' => 'theme_mod',
));
Kirki::add_section('main_menu_settings', array(
'title' => __('Main Menu Settings', 'textdomain'),
'priority' => 30,
));
Kirki::add_field('theme_config_id', array(
'type' => 'text',
'settings' => 'menu_title',
'label' => __('Menu Title', 'textdomain'),
'section' => 'main_menu_settings',
'default' => '',
));
Kirki::add_field('theme_config_id', array(
'type' => 'textarea',
'settings' => 'menu_description',
'label' => __('Menu Description', 'textdomain'),
'section' => 'main_menu_settings',
'default' => '',
));
Kirki::add_field('theme_config_id', array(
'type' => 'text',
'settings' => 'button_label',
'label' => __('Button Label', 'textdomain'),
'section' => 'main_menu_settings',
'default' => '',
));
Kirki::add_field('theme_config_id', array(
'type' => 'text',
'settings' => 'button_link',
'label' => __('Button Link', 'textdomain'),
'section' => 'main_menu_settings',
'default' => '',
));
Kirki::add_field('theme_config_id', array(
'type' => 'select',
'settings' => 'button_target',
'label' => __('Button Target', 'textdomain'),
'section' => 'main_menu_settings',
'default' => '_self',
'choices' => array(
'_self' => __('Same Tab', 'textdomain'),
'_blank' => __('New Tab', 'textdomain'),
),
));
// functions.php
function custom_shortcode_output() {
$menu_title = get_theme_mod('menu_title', '');
$menu_description = get_theme_mod('menu_description', '');
$button_label = get_theme_mod('button_label', '');
$button_link = get_theme_mod('button_link', '');
$button_target = get_theme_mod('button_target', '_self');
ob_start();
?>
<div class="glue-grid__col glue-grid__col--span-5 nav-dropdown-modal--content-heading" id="dropdown-modal-3-label">
<h1 class="glue-headline glue-headline--headline-3 glue-grey-700">
<?php echo esc_html($menu_title); ?>
<span class="decorated-text">
<img class="circle" role="presentation" src="https://kstatic.googleusercontent.com/files/27b9d1efc0c3e55e59edb4f7b5d12d102eba9cf34e1b3e8ba92311ab847ac34324285de403565b06eb66f3ac5345d984c6dde666b93abc97409469f93a5c8433">
</span>
</h1>
<p class="glue-body glue-mod-spacer-3-top glue-grey-700 nav-dropdown-modal--content-desc" id="dropdown-modal-3-content">
<?php echo esc_html($menu_description); ?>
</p>
<a class="nav-dropdown-modal--cta glue-mod-spacer-3-top glue-button glue-button--high-emphasis" href="<?php echo esc_url($button_link); ?>" aria-label="<?php echo esc_attr($button_label); ?>" role="button" data-link="<?php echo esc_url($button_link); ?>" target="<?php echo esc_attr($button_target); ?>">
<?php echo esc_html($button_label); ?>
</a>
</div>
<?php
return ob_get_clean();
}
add_shortcode('custom_shortcode', 'custom_shortcode_output');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment