[wp-trac] [WordPress Trac] #43379: Allow themes to know if they are the parent or child theme
WordPress Trac
noreply at wordpress.org
Wed Feb 21 19:06:10 UTC 2018
#43379: Allow themes to know if they are the parent or child theme
-----------------------------+------------------------------
Reporter: denvercoder9 | Owner:
Type: feature request | Status: new
Priority: normal | Milestone: Awaiting Review
Component: Themes | Version:
Severity: normal | Resolution:
Keywords: | Focuses:
-----------------------------+------------------------------
Comment (by denvercoder9):
Not quite, is_child_theme just lets you know if a child theme is in use if
a child theme is in use it resolves true, if not it resolves false. In my
use case is_child_theme would always resolve true because I'm looking for
functionality specific to a parent/child environment.
I think my example clearly explains.. let me expand
Thefunctionality im looking for
{{{#!php
<?php
//in both functions.php files (both as in parent and child)
$base = is_parent_theme() ? get_template_dir() : get_stylesheet_dir();
//in parent theme's functions.php
require_once($base . '/config/image_sizes.php);
//in child theme's functions.php
require_once($base . '/config/image_sizes.php);
}}}
As it exists presently you have to do...
parent theme's functions.php
{{{#!php
<?php
$base = get_template_dir();
require_once($base . '/config/image_sizes.php);
}}}
child theme's functions.php
{{{#!php
<?php
$base = get_stylesheet_dir();
require_once($base . '/config/image_sizes.php);
}}}
In this usecase I can prevent users cloning my theme for a child theme
from having to update get_template_dir references to get_stylesheet_dir
references. My example is extremely basic on purpose to prove a point. You
could easily accomplish that specific functionality with __DIR__, but
that's just because my example demonstrates the code in functions.php.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/43379#comment:5>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list