theme customizer - How to add "get_theme_mod" inside a shortcode?

I want to make dynamic the content inside a shortcode so I can modify it in the customizer. I created the customizer tab

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
Add a comment  | 

1 Answer 1

Reset to default 2

I 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>

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745383376a4625332.html

相关推荐

  • theme customizer - How to add &quot;get_theme_mod&quot; inside a shortcode?

    I want to make dynamic the content inside a shortcode so I can modify it in the customizer. I created the customizer tab

    4小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信