可自定义颜色的WordPress主题

我目前正在尝试将我制作的Bootstrap单页网站转换为WordPress主题。我需要协助的部分是允许自定义颜色。特别是附加到引导程序的原色和辅助色。

我已经在functions.php中注册了主题定制器, 但是我需要一种方法来实际更改页面上的颜色。

我曾考虑过使用类似下面的内容, 但是我有很多东西使用主色或辅助色, 然后就拥有了所有自举程序。有没有更简单/更快的方法来解决这个问题, 还是我被迫这样做?

function customize_css() {
    $primary = get_theme_mod('primary_colour', '#F0AEAA');
    $secondary = get_theme_mod('secondary_colour', '#2C3E50');
    ?>
        <style>
            /* PRIMARY COLOUR OVERWRITES */
            a {
                color: <?= $primary ?>;
            }
            .bg-primary {
                background-color: <?= $primary ?> !important;
            }

            /* SECONDARY COLOUR OVERWRITES */
            .bg-secondary {
                background-color: <?= $secondary ?> !important;
            }
        </style>
    <?php
}
add_action('wp_head', 'customize_css');

#1


你的代码示例是显示背景颜色的最简单方法。

只是, 你将代码放在主题中的functions.php文件中。

function customize_css() {
    $primary = get_theme_mod('primary_colour', '#F0AEAA');
    $secondary = get_theme_mod('secondary_colour', '#2C3E50');
    ?>
        <style>
            /* PRIMARY COLOUR OVERWRITES */
            a {
                color: <?= $primary ?>;
            }
            .bg-primary {
                background-color: <?= $primary ?> !important;
            }

            /* SECONDARY COLOUR OVERWRITES */
            .bg-secondary {
                background-color: <?= $secondary ?> !important;
            }
        </style>
    <?php
}
add_action('wp_head', 'customize_css');

祝一切顺利!!

来源:

https://www.srcmini02.com/64567.html

微信公众号
手机浏览(小程序)

Warning: get_headers(): SSL operation failed with code 1. OpenSSL Error messages: error:14090086:SSL routines:ssl3_get_server_certificate:certificate verify failed in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57

Warning: get_headers(): Failed to enable crypto in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57

Warning: get_headers(https://static.shanhubei.com/qrcode/qrcode_viewid_37431.jpg): failed to open stream: operation failed in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57
0
分享到:
没有账号? 忘记密码?