博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
How to Create a WordPress Child Theme
阅读量:6963 次
发布时间:2019-06-27

本文共 3637 字,大约阅读时间需要 12 分钟。

hot3.png

We’ve all been there: the crossroads of updating your theme and overwriting the edits you made to it. Either you have to leave your theme out of date or erase all the work you put into customizing it. Maybe you’re lucky and the changelog specifies which files are new so you can update manually, but this can be meticulous and time wasting. There must be an easier way!

Why Child Themes are Useful

 are the root of customization. They allow you to customize your themes, while keeping the main theme intact so updating won’t erase your changes. Basically, a child theme is a ‘new’ theme that simply loads the framework from the parent theme. This way, whenever you update the parent theme, the child theme is ‘updated’ too. Neat!

Note: For minor CSS changes, use the Custom CSS box located in your Theme Options; for any PHP customization, use a Child Theme.

How to Create a WordPress Child Theme for 2014 Theme

The process to create a WordPress child theme is relatively easy, but some themes may take extra effort. For this example, we’ll use the latest WordPress Theme 2014.

1. Create Child Theme Directory

The first step is to create a ‘new theme’ that WordPress can load in Appearance>Themes. FTP to your server, navigate to /wp-content/themes/ and create a new folder called ‘twentyfourteen-child’.

How to Create a WordPress Child Theme

Note: The name of this folder does not matter, it is for internal labeling purposes and WordPress does not read it.

2. Create Child Theme Stylesheet

This is where things get interesting. Open your new child theme directory and create a new file called style.css.

How to Create a WordPress Child Theme

In this file, you’ll get to name your theme and set up all the metadata that shows in Appearance>Themes. This file will also tell WordPress where the parent theme is, so make sure to use the correct URI.

Default style.css code:

  1. Theme Name: Twenty Fourteen Child

  2. Theme URI: http://example.com/twenty-fourteen-child/

  3. Description: Twenty Fourteen Child Theme

  4. Author: John Doe

  5. Author URI: http://example.com

  6. Template: twentyfourteen

  7. Version: 1.0.0

  8. Tags: light, dark, two-columns, right-sidebar, responsive-layout, accessibility-ready

  9. Text Domain: twenty-fourteen-child

  10. */

  11. url("../twentyfourteen/style.css");

  12. /* =Theme customization starts here

  13.  

  14. -------------------------------------------------------------- */

Note: The ../ notation refers to the parent folder. In this case, it refers to /wp-content/themes/.

3. Extend the Functions.php File

The cool thing about a child theme is that it can overwrite the parent theme files without actually editing them. Simply add the same file to the child theme directory and it will overwrite it. For example, if you wanted a different header, you would add header.php to your child theme directory.

This is not the case for functions.php however. For child themes, creating a new functions.php will simply extend the old file. This is so you can add new functions without the need to duplicate the entire functions.php file. In your child theme directory, create a file called functions.php and make sure to add the PHP tag to the top and bottom. Afterwards, you can add any new functions!

How to Create a WordPress Child Theme

Default functions.php code:

// Custom Function to Includefunction favicon_link() {    echo '' . "\n";} add_action( 'wp_head', 'favicon_link' ); ?>  //Closing PHP tag

Note: To quickly make small modifications to page templates, just copy the parent theme file to the child theme directory.

That’s It

You can now activate your child theme in Appearance>Themes and can edit any theme files you want without disrupting the critical theme updates!

So, what changes will you make to your child theme?

转载于:https://my.oschina.net/ajian2014/blog/303498

你可能感兴趣的文章
R478规划及实施—理想丰满、现实骨感
查看>>
FreeBSD scp xftp 无法使用时,考虑sftp。
查看>>
使用计划任务定时重启Server
查看>>
RedisCluster工具类
查看>>
我的友情链接
查看>>
htpasswd用法(即配置SVN密码加密)
查看>>
Android Service完全解析,关于服务你所需知道的一切(上)
查看>>
日志打印中的入参
查看>>
Microsoft Dynamics CRM 2013 配置之 添加配置 域证书服务器 和 ADFS
查看>>
your windows password does not match your Notes password
查看>>
TCP: time wait bucket table overflow解决方法
查看>>
CSS样式中设置table的cellspacing属性
查看>>
The method getTextContent() is undefined for the type Node
查看>>
iPhone动画属性详解
查看>>
fatal error: 'openssl/err.h' file not found
查看>>
zabbix实现 SAS 6/iR 型号 Raid信息监控
查看>>
RHEL Centos7 Yum网络源与光盘源设置
查看>>
一条sql语句实现一维表生成二维表格
查看>>
我的友情链接
查看>>
从“赢”字诠释解读成功的必备要素(一)
查看>>