I want to make dynamic the content inside a shortcode so I can modify it in the customizer. I created the customizer tabs. Now, I want to create a shortcode to place it anywhere in the page while being able to manipulate in the customizer.
This is the code I'm working on. Thanks!
<?php
/*
Plugin Name: ....
*/
// Exit if accessed directly
if(!defined('ABSPATH')){
exit;
}
function customizer_inject_css()
{
?>
<style type="text/css">
:root {
--theme-page-width: <?php echo get_theme_mod('theme_page_width', '1366px');
?>!important;
}
.stm-template-car_dealer_two .container {
max-width: var(--theme-page-width)!important;
}
</style>
<?php
}
add_shortcode( 'ui_gallery','function_gallery_shortcode' );
function function_gallery_shortcode(){
$dynamic_h1 = "<h1>" . get_theme_mod('dymanich1') . "</h1>";
return $dynamic_h1;
}
add_action( 'wp_head', 'customizer_inject_css');
add_action("customize_register","register_customizer");
function register_customizer( WP_Customize_Manager $wp_customize) {
$wp_customize->add_panel( 'theme_extension_panel',
array(
'priority' => 2,
'capability' => 'edit_theme_options',
'title' => __('Theme Extensions'),
'description' => __(''),
) );
$wp_customize->add_section("general_section", array(
"title" => __("General"),
"priority" => 1,
"panel" => "theme_extension_panel"
));
$wp_customize->add_setting( 'theme_page_width', array(
"transport" => "refresh",
"default" => "",
) );
$wp_customize->add_control(
new WP_Customize_Control(
$wp_customize,
'theme_page_width_control',
array(
'label' => __(''),
'section' => 'general_section',
'settings' => 'theme_page_width',
"type" => "text",
"description" => "Max Width",
'priority' => 1
) )
);
$wp_customize->add_setting( 'dynamich1', array(
"transport" => "refresh",
"default" => "",
) );
$wp_customize->add_control(
new WP_Customize_Control(
$wp_customize,
'dynamich1_control',
array(
'label' => __(''),
'section' => 'general_section',
'settings' => 'dynamich1',
"type" => "text",
"description" => "display h1",
'priority' => 1
) )
);
}
I want to make dynamic the content inside a shortcode so I can modify it in the customizer. I created the customizer tabs. Now, I want to create a shortcode to place it anywhere in the page while being able to manipulate in the customizer.
This is the code I'm working on. Thanks!
<?php
/*
Plugin Name: ....
*/
// Exit if accessed directly
if(!defined('ABSPATH')){
exit;
}
function customizer_inject_css()
{
?>
<style type="text/css">
:root {
--theme-page-width: <?php echo get_theme_mod('theme_page_width', '1366px');
?>!important;
}
.stm-template-car_dealer_two .container {
max-width: var(--theme-page-width)!important;
}
</style>
<?php
}
add_shortcode( 'ui_gallery','function_gallery_shortcode' );
function function_gallery_shortcode(){
$dynamic_h1 = "<h1>" . get_theme_mod('dymanich1') . "</h1>";
return $dynamic_h1;
}
add_action( 'wp_head', 'customizer_inject_css');
add_action("customize_register","register_customizer");
function register_customizer( WP_Customize_Manager $wp_customize) {
$wp_customize->add_panel( 'theme_extension_panel',
array(
'priority' => 2,
'capability' => 'edit_theme_options',
'title' => __('Theme Extensions'),
'description' => __(''),
) );
$wp_customize->add_section("general_section", array(
"title" => __("General"),
"priority" => 1,
"panel" => "theme_extension_panel"
));
$wp_customize->add_setting( 'theme_page_width', array(
"transport" => "refresh",
"default" => "",
) );
$wp_customize->add_control(
new WP_Customize_Control(
$wp_customize,
'theme_page_width_control',
array(
'label' => __(''),
'section' => 'general_section',
'settings' => 'theme_page_width',
"type" => "text",
"description" => "Max Width",
'priority' => 1
) )
);
$wp_customize->add_setting( 'dynamich1', array(
"transport" => "refresh",
"default" => "",
) );
$wp_customize->add_control(
new WP_Customize_Control(
$wp_customize,
'dynamich1_control',
array(
'label' => __(''),
'section' => 'general_section',
'settings' => 'dynamich1',
"type" => "text",
"description" => "display h1",
'priority' => 1
) )
);
}
Share
Improve this question
edited Feb 12, 2019 at 23:22
MediaFormat
2831 silver badge11 bronze badges
asked Feb 12, 2019 at 19:18
andrew ricoandrew rico
32 bronze badges
1 Answer
Reset to default 2I would comment, but lack the pointage... You seem to be on the right track:
I see that your shortcode callback and the function are named
differently: (f_gallery_shortcode
/ function_gallery_shortcode
).
Try this:
add_shortcode( 'ui_gallery','function_gallery_shortcode' );
function function_gallery_shortcode(){
$dynamic_h1 = "<h1>" . get_theme_mod('dynamich1') . "</h1>";
return $dynamic_h1;
}
now using [ui_gallery]
in your posts, should return the results of your Customizer value <h1>dymanich1</h1>