Make WordPress Core

Opened 5 years ago

Closed 5 years ago

Last modified 5 years ago

#13084 closed defect (bug) (wontfix)

Loading Parent Theme functions BEFORE Child Theme functions

Reported by: oncletom Owned by:
Milestone: Priority: normal
Severity: normal Version: 2.9.2
Component: Themes Keywords: parent, child, theme
Focuses: Cc:



I am creating a child theme for a mobile purpose.
The goal was to complete parent theme's functions.php and modify already configured behavior from the child theme to improve things.

It would be more logical that child theme's functions.php be loaded AFTER parent theme's one... like it is done for template file overloading.

The parent theme is not aware of the child one.
The opposite is true.

if ( TEMPLATEPATH !== STYLESHEETPATH && file_exists(STYLESHEETPATH . '/functions.php') )
	include(STYLESHEETPATH . '/functions.php');
if ( file_exists(TEMPLATEPATH . '/functions.php') )
	include(TEMPLATEPATH . '/functions.php');

should be replaced by

if ( file_exists(TEMPLATEPATH . '/functions.php') )
	include(TEMPLATEPATH . '/functions.php');
if ( TEMPLATEPATH !== STYLESHEETPATH && file_exists(STYLESHEETPATH . '/functions.php') )
	include(STYLESHEETPATH . '/functions.php');

in wp-settings.php

Patch is attached.

Attachments (1)

wp-settings.patch (756 bytes) - added by oncletom 5 years ago.

Download all attachments as: .zip

Change History (5)

@oncletom5 years ago

comment:1 @demetris5 years ago

  • Cc dkikizas@… added

One reason it’s done this way is to allow parent themes to make their functions pluggable by declaring them conditionally. E.g., the parent says:

if (!function_exists('mega_clever_function')) {
    function mega_clever_function() {
        Do mega clever stuff!

Then the child comes along and does not like mega_clever_function. So it simply does:

function mega_clever_function() {
    Do different clever stuff!

You can see examples in the functions.php of the new default theme, Twenty Ten. (But that order of loading the two files was there long before 2010.)

comment:2 @greenshady5 years ago

There were times when I wished the files were loaded in this order, but it's too late in the game to make this change. This is how it's been done for years now. I imagine there'll be some backwards-compatibility issues.

Assuming your parent theme's functions.php is coded well, it shouldn't be tough to override its functionality even if it's loaded last.

comment:3 @dd325 years ago

  • Milestone Unassigned deleted
  • Resolution set to wontfix
  • Status changed from new to closed

I agree with most of the points above, I've wanted it to happen the other way around a few times, but ultimately, theres a reason it was made the way it is, and to change it now would break a lot of themes.. with little benefit.

comment:4 @nacin5 years ago

It's also very easy for a child theme to allow the parent theme functions to be loaded first, by simply delaying execution of anything until the after_setup_theme hook.

Note: See TracTickets for help on using tickets.