2017-11-03 218 views
0

我已经开始在wordpress主题上工作,需要使它成为一个儿童主题,以防止更新改变我的网站和自定义。父母对儿童主题 - WordPress的

有没有可以做这个的wat?

+0

你可能会更好地服务于https://wordpress.stackexchange.com/ –

+0

看看这里:https://codex.wordpress.org/Child_Themes – mmm

回答

0

你只需要按照以下3个步骤:

1)在/可湿性粉剂内容的主题创建一个文件夹/主题/:

“建议(虽然不是必需的,尤其是如果你正在创建一个供公众使用的主题),你的子主题目录的名称会附加'-child'。“。

这里创建的每个文件都会覆盖父主题中的文件。例如,您可以创建新的页面模板:https://developer.wordpress.org/themes/template-files-section/page-template-files/或覆盖现有的模板。

2)创建是一个style.css的文件,并开始它:

/* 
Theme Name: Twenty Fifteen Child 
Theme URI: http://example.com/twenty-fifteen-child/ 
Description: Twenty Fifteen Child Theme 
Author:  John Doe 
Author URI: http://example.com 
Template:  twentyfifteen 
Version:  1.0.0 
License:  GNU General Public License v2 or later 
License URI: http://www.gnu.org/licenses/gpl-2.0.html 
Tags:   light, dark, two-columns, right-sidebar, responsive-layout, accessibility-ready 
Text Domain: twenty-fifteen-child 
*/ 

这里添加您的自定义样式。更多信息:https://codex.wordpress.org/Theme_Development#Theme_Stylesheet

3)创建的functions.php

在这个文件中,你可以添加新的功能,你的孩子的主题或修改现有的。

您还需要在这里入队您的父主题的CSS和JS,以及您在子主题上创建的新CSS和JS。类似的东西会做大部分的时间:

<?php 
function my_theme_enqueue_styles() { 

    $parent_style = 'parent-style'; // This is 'twentyfifteen-style' for the Twenty Fifteen theme. 

    wp_enqueue_style($parent_style, get_template_directory_uri() . '/style.css'); 
    wp_enqueue_style('child-style', 
     get_stylesheet_directory_uri() . '/style.css', 
     array($parent_style), 
     wp_get_theme()->get('Version') 
    ); 
} 
add_action('wp_enqueue_scripts', 'my_theme_enqueue_styles'); 
?> 

现在,您可以添加自定义的简(https://codex.wordpress.org/Shortcode_API),窗口小部件区域(https://codex.wordpress.org/Widgetizing_Themes)等。

更多的文档关于儿童主题:https://codex.wordpress.org/Child_Themes