php - 如何在wordpress自定义中添加颜色选项

标签 php css wordpress

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

最佳答案

读这个:

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 - 如何在wordpress自定义中添加颜色选项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36786520/

相关文章:

php - 我可以使用 `??` (空合并运算符)而不是空吗?

php - 找出php中两个数组的区别

php - 用于对 magento 集合进行排序的多个字段

css - 通过 less 生成 CSS 组

css - 如何使用具有 IE7 和 8 兼容性的图像制作 Fluid in width 圆 Angular 搜索框?

php - 重定向/index.php - WordPress

wordpress - 从命令行调用wordpress?

php - 将 Zurb Foundation 5 集成到 Wordpress 3.8 主题中

php - 使用AWS SDK查询存储类别

jquery - 动态加载的 Masonry 图像重叠