2017-11-03 226 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