如何为你的wordpress主题添加子主题child
子主题的创建很简单:
1、首先在主题文件夹下(wp-content hemes)建立一个文件夹,用来存放子主题的所有文件,例如:twentytwelve-child。
2、在twentytwelve-child文件夹下新建一个style.css文件,该文件是必须的。将以下代码粘贴进去:
/*
Theme Name: Twenty Twelve Child (子主题名称,必须)
Theme URI: http://www.**.com (主题url)
Description: Child theme for the Twenty Twelve theme (主题描述)
Author: ** (主题作者)
Author URI: http://www.**.com (作者uri)
Template: twentytwelve (父主题目录名称,必须)
Version: 1.0.0 (版本号)
*/
括号的字要去掉,此时就可以在后台-外观-主题中激活该子主题。
3.创建function.php文件,加上父主题的CSS加载代码
/**-------------------------------------------------------------------------------**/
/**子主题CSS调用***/
/**-------------------------------------------------------------------------------**/
add_action( 'wp_enqueue_scripts', 'enqueue_parent_styles' );
function enqueue_parent_styles() {
wp_enqueue_style( 'parent-style', get_template_directory_uri().'/style.css' );
}
4.后台开启子主题即可
5.建个主页模板
<?php
/**
* Template Name:FullWidth (模板名称)
*
* @package WordPress
* @subpackage illdy
*/
?>