编辑WordPress主题
这是一种在不触及原始文件的情况下,通过修改备份文件(称为子主题)来使用的方法。
- 为了方便识别正在使用的子主题,在“wp-content/themes”目录下创建一个新文件夹,将主题名称结合起来。(例如:如果原始主题是“twentyfifteen”,则创建名为“twentyfifteen-child”的文件夹)
- 将原始主题的“style.css”复制到子主题文件夹中,并将“Theme Name”和“Template”修改如下:
/* Theme Name: Twenty Fifteen Child Theme URI: https://wordpress.org/themes/twentyfifteen/ Template: twentyfifteen Author: the WordPress team Author URI: https://wordpress.org/ Description: 我们2015年的默认主题简洁、以博客为中心,并且设计清晰。Twenty Fifteen简单明了的排版在各种屏幕尺寸上均易于阅读,适合多种语言。我们采用了移动优先的设计理念,这意味着无论访问者是通过智能手机、平板电脑、笔记本电脑还是台式电脑访问,您的内容都居于中心。 Version: 1.5 License: GNU General Public License v2或更高版本 License URI: http://www.gnu.org/licenses/gpl-2.0.html Tags: black, blue, gray, pink, purple, white, yellow, dark, light, two-columns, left-sidebar, fixed-layout, responsive-layout, accessibility-ready, custom-background, custom-colors, custom-header, custom-menu, editor-style, featured-images, microformats, post-formats, rtl-language-support, sticky-post, threaded-comments, translation-ready Text Domain: twentyfifteenTemplate: twntyfifteen 此主题与WordPress一样,采用GPL许可。 用它来创造一些酷的东西,享受其中,并与他人分享您所学到的内容。 */
- 在子主题文件夹中使用以下代码创建“functions.php”文件。
<?php add_action( 'wp_enqueue_scripts', 'theme_enqueue_styles' ); function theme_enqueue_styles() { wp_enqueue_style( 'parent-style', get_template_directory_uri() . '/style.css' ); } ?> - 将原主题的“screenshot.png”复制到子主题文件夹中。
- 复制原主题的文件到子主题文件夹中后,您可以根据需要进行修改和使用。
(参考 : http://codex.wordpress.org/Child_Themes)











Leave a Reply