【问题标题】:how to add color option in wordpress customize如何在wordpress自定义中添加颜色选项
【发布时间】:2016-08-15 15:41:00
【问题描述】:

我正在开发一个 wordpress 主题,我喜欢在自定义页面中添加一个颜色选项,以便管理员可以更改背景颜色、文本颜色、链接颜色等。我没有安装任何插件除了“Akismet”和“mytheme”(mytheme 是我的主题的名称)之外的 wordpress 目录,所有主题在自定义页面中都有该选项。 我的问题是如何在“站点标识”选项之后出现的自定义页面中添加该颜色选项。 谢谢

【问题讨论】:

标签: php css wordpress


【解决方案1】:

阅读:

Customizer WordPress

这样的事情应该可以工作:

function mytheme_customize_register( $wp_customize ) {
    //All our sections, settings, and controls will be added here
    $wp_customize->add_setting( 'header_textcolor' , array(
        'default'     => "#000000",
        'transport'   => 'refresh',
    ) );

    $wp_customize->add_control( new WP_Customize_Color_Control( $wp_customize, 'header_textcolor', array(
        'label'        => __( 'Header Color', 'mytheme' ),
        'section'    => 'colors',
    ) ) );
}
add_action( 'customize_register', 'mytheme_customize_register' );

function mytheme_customize_css()
{
    ?>
    <style type="text/css">
        h2 { color: #<?php echo get_theme_mod('header_textcolor', "#000000"); ?>; }
    </style>
    <?php
}
add_action( 'wp_head', 'mytheme_customize_css');

通过wp_head();输出

<style type="text/css">
     h1 {color:#000000;}
</style>

【讨论】:

  • 感谢回复..我已将 PHP 代码粘贴到 functions.php 文件中,并将 CSS 粘贴到 style.css 文件中.....现在页面不显示任何内容
  • @ShanBiswas,请查看更新的答案。你让它工作了吗?
  • 你好......我已经把你更新的代码放在上面了,现在可以工作了,无论如何谢谢你变化很大......!!
  • @ShanBiswas,很高兴我能提供帮助,请接受答案并投票 :)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-04-11
  • 1970-01-01
  • 2021-09-25
  • 1970-01-01
  • 2018-10-08
相关资源
最近更新 更多