How to Override PHP Files in Your Child Theme

I figured how how to override an arbitrary file in a child theme. It is ALMOST as simple as placing the override file in the corresponding folder for the child theme. The step I didn’t know about, was to add a require_once() for the specific file in the child theme’s functions.php. Here is my example step by step:

My example is how to replace the font list in Customizr theme, with my own font list.

WordPress admin screen showing customizer for Customizr theme's Google Fonts setting

1) If I were to “hack” the parent theme to make this change, I’d change the file wp-content/themes/customizr/core/init-base.php

2) Make a copy of core/init-base.php, make your changes, and place it in the child theme’s folder: wp-content/themes/customizr-child/core/init-base.php.  Note you must create a “core” folder in which to place init-base.php — you must replicate the full path of the overridden file (or whatever file you refer to in step 3).

Screenshot of Windows Explorer
The overriding file is in the “core” folder

3) Modify your child theme’s functions.php to include the overriding file, by adding the following line:

require_once( get_stylesheet_directory() . 'core/init-base.php' );

Why? According to the WordPress codex: https://codex.wordpress.org/Child_Themes, about half way down, see …

Referencing / Including Files in Your Child Theme

When you need to include files that reside within your child theme’s directory structure, you will use get_stylesheet_directory(). Because the parent template’s style.css is replaced by your child theme’s style.css, and your style.css resides in the root of your child theme’s subdirectory, get_stylesheet_directory() points to your child theme’s directory (not the parent theme’s directory).

Here’s an example, using require_once, that shows how you can use get_stylesheet_directory when referencing a file stored within your child theme’s directory structure.

require_once( get_stylesheet_directory() . '/my_included_file.php' );

In my case, I’ll add this line to my child theme’s functions.php:

require_once( get_stylesheet_directory() . 'core/init-base.php' );

Screenshot of TextPad with Filezilla behind
Adding the “require_once” line to the child theme’s functions.php

4) Upload the new file and the modified functions.php to your web server, and the next time you access the font choices in the customizr, you’ll see your new font list.

Twenty Sixteen Theme

I am trying out the Twenty Sixteen Theme at my second WordPress practice site, wp.elizapro.com. I changed the background color and created a child theme.

Website home page with header imageMy child theme differs from the parent theme only in that there’s a custom CSS file.  More about Twenty Sixteen Theme:

  • Introduction
  • Download (this page includes a download button)
  • Features (it took me a while to find this page. Why?)
    • The “Features” are NOT described in the sidebar list entitled “Features.” Each of those links shows you a selection of WordPress themes that let you customize that feature … as far as I can tell
    • I can’t find further details on this theme’s features. I thought there was more than the custom colors and header described somewhere. In the meantime, as with any Theme, to see its theme-specific customizations go to your WP dashboard -> Appearance -> Themes, find your theme and hit Customize.

How Did my WordPress get Automatically Updated?

I got an email the other day saying my site was automatically updated to WordPress 4.3.2. How did that happen? I’m self-hosting this website, and I’d not logged in for a couple of months.

It turns out whenever your site requests a page, that is, someone visits your website, this page load will trigger a check for updates.

The update runs in the background via wp-cron. wp_cron checks whether there are any scheduled events in the database. If yes it calls spawn_cron(), which starts another PHP process to do all the actual work.

Lots of processes in WordPress are handled by the cron system: scheduled post publishing, processing pings, update checks, etc.

The automatic update only happens when wordpress.org releases a new minor or security update. Otherwise (for a “major” release like WP 4.3 to 4.4) you must do the update manually by logging in to the back end.

I got this information from http://wordpress.stackexchange.com/questions/131334/how-exactly-do-automatic-updates-work. Thanks to “DisgruntledGoat” for asking and others for answering and explaning.

Where are my Pages? Page Permalinks & Featured Image

The permalink of my first page is here: wp.elizahost.com/here-is-my-test-page/

Perhaps I need to create a menu bar?

And I appreciate how post and page’s “featured image” feature makes it really easy to provide an image for each page or post, but can I make the “featured image” float right near the top of the post text, rather than sitting above the post or page title?