我想在一个短代码中动态显示内容,以便在自定义程序中修改它。我创建了customizer选项卡。现在,我想创建一个短代码,将其放置在页面中的任何位置,同时能够在自定义程序中进行操作。
这就是我正在研究的代码。谢谢
<?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
) )
);
}