是否为自定义页脚颜色添加_THEME_SUPPORT?

时间:2019-04-25 作者:Joey

我已经看到了“自定义页眉”、“自定义背景”和“自定义徽标”的主题支持(add\\u theme\\u support),但不支持页脚(页脚颜色或图像)。

是否没有选项允许用户通过“外观”-->“自定义”选择页脚颜色或图像?

谢谢你的建议!

2 个回复
最合适的回答,由SO网友:Vishwa 整理而成

您可以在主题函数中使用以下类。php文件。主题自定义API将从此呈现主题自定义程序上的自定义颜色选择器控件。

class MyTheme_Customize {
public static function register ( $wp_customize ) {
$wp_customize->add_section( \'mytheme_options\', 
array(
\'title\'       => __(\'MyTheme Options RR\', \'twentynineteen\' ), //Visible title of section
\'priority\'    => 3, //Determines what order this appears in
\'capability\'  => \'edit_theme_options\', //Capability needed to tweak
\'description\' => __(\'Allows you to customize some example settings for MyTheme.\', \'twentynineteen\'), //Descriptive tooltip
) 
);

//2. Register new settings to the WP database...
$wp_customize->add_setting( \'link_textcolor\',
array(
\'default\'    => \'#333333\', //Default setting/value to save
\'type\'       => \'theme_mod\', //Is this an \'option\' or a \'theme_mod\'?
\'capability\' => \'edit_theme_options\', //Optional. Special permissions for accessing this setting.
\'transport\'  => \'refresh\', //What triggers a refresh of the setting? \'refresh\' or \'postMessage\' (instant)?
\'sanitize_callback\'  => \'esc_attr\', //sanitization (optional?)
) 
);      

//3. Finally, we define the control itself (which links a setting to a section and renders the HTML controls)...
$wp_customize->add_control( new WP_Customize_Color_Control(
$wp_customize, //Pass the $wp_customize object (required)
\'mytheme_link_textcolor\', //Set a unique ID for the control
array(
\'label\'      => __( \'Footer Background Color\', \'twentynineteen\' ), //Admin-visible name of the control
\'settings\'   => \'link_textcolor\', //Which setting to load and manipulate (serialized is okay)
\'priority\'   => 10, //Determines the order this control appears in for the specified section
\'section\'    => \'colors\', //ID of the section this control should render in (can be one of yours, or a WordPress default section)
) 
) );

//4. We can also change built-in settings by modifying properties. For instance, let\'s make some stuff use live preview JS...
$wp_customize->get_setting( \'blogname\' )->transport = \'refresh\';
$wp_customize->get_setting( \'blogdescription\' )->transport = \'refresh\';
$wp_customize->get_setting( \'header_textcolor\' )->transport = \'refresh\';
$wp_customize->get_setting( \'background_color\' )->transport = \'refresh\';

}

public static function header_output() {
?>
<!--Theme Customizer CSS--> 
<style type="text/css"> 
<?php self::generate_css(\'#footer\', \'color\', \'link_textcolor\'); ?>
</style> 
<!--/Theme Customizer CSS-->
<?php
}

public static function generate_css( $selector, $style, $mod_name, $prefix=\'\', $postfix=\'\', $echo=true ) {
$return = \'\';
$mod = get_theme_mod($mod_name);
if ( ! empty( $mod ) ) {
$return = sprintf(\'%s { %s:%s; }\',
$selector,
$style,
$prefix.$mod.$postfix
);
if ( $echo ) {
echo $return;
}
}
return $return;
}
}

// Setup the Theme Customizer settings and controls...
add_action( \'customize_register\' , array( \'MyTheme_Customize\' , \'register\' ) );

// Output custom CSS to live site
add_action( \'wp_head\' , array( \'MyTheme_Customize\' , \'header_output\' ) );
Note: 您应该将主题名称(Twenty十九)更改为您的主题名称。只需使用搜索和替换

SO网友:Babita Verma

我有相同的查询,但我需要在页眉和页脚添加颜色、字体大小和字体样式。如果我将此功能添加到自定义主题中,那么它会在customizer上显示页脚的颜色选项,而在前端则不会更改颜色。

提前谢谢你巴比塔

相关推荐

WooThemes-供应商/预订-允许供应商管理资源

我正在尝试从WooThemes为bookings插件带来新功能。在组合预订和供应商插件时,不允许供应商用户管理资源(资源是自定义帖子)。我将新功能添加到资源自定义帖子中,然后将这些功能添加到供应商角色(通过用户角色插件)现在,资源显示在供应商角色的管理菜单中,但当我尝试添加新资源时,会出现“您无权访问此页面”错误。我添加的新功能:https://i.stack.imgur.com/OCDlV.png添加到角色的功能:https://i.stack.imgur.com/5t696.png使用角色登录时显示的