最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

theme development - "add_theme_support" for custom footer color?

programmeradmin2浏览0评论

I've seen theme support (add_theme_support) for "custom-header", "custom-background" and "custom-logo", but not for footer (footer colur or image).

Is there no option to let users choose footer color or image via "Appearance" --> "Customize"?

Thank you for your advice!

I've seen theme support (add_theme_support) for "custom-header", "custom-background" and "custom-logo", but not for footer (footer colur or image).

Is there no option to let users choose footer color or image via "Appearance" --> "Customize"?

Thank you for your advice!

Share Improve this question edited Apr 25, 2019 at 3:57 Vishwa 3762 silver badges17 bronze badges asked Apr 25, 2019 at 2:20 JoeyJoey 235 bronze badges
Add a comment  | 

2 Answers 2

Reset to default 2

You can use following class put inside your theme's functions.php file. Theme Customization API will render the custom color selector control on the Theme customizer from this.

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: You should change theme name (twentynineteen) to your theme's name. just use search and replace

I have the same query but i need to add color, fontsize and fontstyle at header and footer both. if i add this function to my custom theme then it shows color options for footer
at customizer only its not changing color at the frontend.

Thank you in advance Babita

发布评论

评论列表(0)

  1. 暂无评论
ok 不同模板 switch ($forum['model']) { /*case '0': include _include(APP_PATH . 'view/htm/read.htm'); break;*/ default: include _include(theme_load('read', $fid)); break; } } break; case '10': // 主题外链 / thread external link http_location(htmlspecialchars_decode(trim($thread['description']))); break; case '11': // 单页 / single page $attachlist = array(); $imagelist = array(); $thread['filelist'] = array(); $threadlist = NULL; $thread['files'] > 0 and list($attachlist, $imagelist, $thread['filelist']) = well_attach_find_by_tid($tid); $data = data_read_cache($tid); empty($data) and message(-1, lang('data_malformation')); $tidlist = $forum['threads'] ? page_find_by_fid($fid, $page, $pagesize) : NULL; if ($tidlist) { $tidarr = arrlist_values($tidlist, 'tid'); $threadlist = well_thread_find($tidarr, $pagesize); // 按之前tidlist排序 $threadlist = array2_sort_key($threadlist, $tidlist, 'tid'); } $allowpost = forum_access_user($fid, $gid, 'allowpost'); $allowupdate = forum_access_mod($fid, $gid, 'allowupdate'); $allowdelete = forum_access_mod($fid, $gid, 'allowdelete'); $access = array('allowpost' => $allowpost, 'allowupdate' => $allowupdate, 'allowdelete' => $allowdelete); $header['title'] = $thread['subject']; $header['mobile_link'] = $thread['url']; $header['keywords'] = $thread['keyword'] ? $thread['keyword'] : $thread['subject']; $header['description'] = $thread['description'] ? $thread['description'] : $thread['brief']; $_SESSION['fid'] = $fid; if ($ajax) { empty($conf['api_on']) and message(0, lang('closed')); $apilist['header'] = $header; $apilist['extra'] = $extra; $apilist['access'] = $access; $apilist['thread'] = well_thread_safe_info($thread); $apilist['thread_data'] = $data; $apilist['forum'] = $forum; $apilist['imagelist'] = $imagelist; $apilist['filelist'] = $thread['filelist']; $apilist['threadlist'] = $threadlist; message(0, $apilist); } else { include _include(theme_load('single_page', $fid)); } break; default: message(-1, lang('data_malformation')); break; } ?>