我正在尝试添加一个自定义控件来更改网站上所有标题的颜色,而无需将其硬编码到style.css
是否有一个示例代码可以作为使用我的子主题实现此功能的参考?
我正在尝试添加一个自定义控件来更改网站上所有标题的颜色,而无需将其硬编码到style.css
是否有一个示例代码可以作为使用我的子主题实现此功能的参考?
据我所知,颜色选择器的主题定制器中没有Wordpress标准控件。但您可以将其添加到新类中。保罗·安德伍德(PaulUnderwood)为添加自定义控件制作了一个精彩的教程here! 并给出了包含颜色选择器的示例github. (注:请注意下面WestonRuter的重要评论,WP中现在有一个颜色选择器控件)。一种更简单的方法是创建一个文本字段并将十六进制值放入其中。因此,您必须在函数中创建设置和控件。php。函数中的代码。php可能如下所示:
function yourtheme_customize_register($wp_customize) {
//Add new Section for Theme
$wp_customize->add_section(\'yourtheme_theme_section\', array(
\'title\' => __(\'yourtheme Settings\', \'yourtheme\'),
\'priority\' => 30,
));
// Add new Setting
$wp_customize->add_setting(\'headings_color\', array(
\'default\' => __(\'Please enter a Quote in Customizer\', \'yourtheme\'),
));
// Add new Control
$wp_customize->add_control(\'headings_color_control\', array(
\'label\' => __(\'hex color\', \'yourtheme\'),
\'section\' => \'your_theme_section\',
\'settings\' => \'headings_color\',
\'type\' => \'text\',
));
add_action(\'customize_register\', \'yourtheme_customize_register\');
您可以使用模板文件(例如header.php)中Customizer的值和get\\u theme\\u mod()函数。e、 g。 <style> h1, h2, h3 {color: <?php echo get_theme_mod(\'headings_color\') ;?>;}</style>
希望这对你有帮助。我遵循wordpress codex网站上关于通过插件创建管理主题的说明。我激活了插件,但我的样式表没有包含在<head>.. 这是我的代码:add_action( \'admin_init\', \'kd_plugin_admin_init\' ); add_action( \'admin_menu\', \'kd_plugin_admin_menu\' ); function kd_plugin_admin_init() { /* Register