[wp-trac] [WordPress Trac] #30797: New function for parent theme stylesheet uri
WordPress Trac
noreply at wordpress.org
Sat Dec 20 18:36:40 UTC 2014
#30797: New function for parent theme stylesheet uri
----------------------------+-----------------------------
Reporter: grapplerulrich | Owner:
Type: enhancement | Status: new
Priority: normal | Milestone: Awaiting Review
Component: Themes | Version: trunk
Severity: normal | Keywords:
Focuses: |
----------------------------+-----------------------------
= Request
I would like to propose a new function to fetch the parent theme. I have
attached a patch.
{{{
/**
* Retrieve URI of current parent theme stylesheet.
*
* The stylesheet file name is 'style.css' which is appended to {@link
* get_template_directory_uri() stylesheet directory URI} path.
*
* @since 4.2.0
*
* @return string
*/
function get_parent_stylesheet_uri() {
$template_dir_uri = get_template_directory_uri();
$parent_stylesheet_uri = $stylesheet_dir_uri . '/style.css';
/**
* Filter the URI of the current parent theme stylesheet.
*
* @since 4.2.0
*
* @param string $parent_stylesheet_uri Stylesheet URI for the
current parent theme.
* @param string $template_dir_uri Stylesheet directory URI
for the current parent theme.
*/
return apply_filters( 'parent_stylesheet_uri',
$parent_stylesheet_uri, $template_dir_uri );
}
}}}
= Background
The reason for adding this was there was a discussion how child themes
should load the parent styles.css. Using @import is not best solution. The
solution would be for the parent themes to load the styles for the child
theme. I created a [https://github.com/Automattic/_s/pull/638 PR] to do it
in _s. The code looked like this but I realized this was not the best
method. The problem with this method is that it is not possible to load a
stylesheet between the parent theme and child theme as the order changes
when you activate a child theme.
My temporary solution for a theme would be add the function
`_s_get_parent_stylesheet_uri()` to the theme like this:
https://github.com/grappler/_s/commit/3fd84b4179f727bb24a32bfd23fcef9be79033f4
By adding `get_parent_stylesheet_uri()` to WordPress core all themes could
use this function and the code in the theme would look like this.
{{{
function _s_scripts() {
wp_enqueue_style( '_s-style', get_parent_stylesheet_uri() );
if ( is_child_theme() ) {
wp_enqueue_style( '_s-child-style', get_stylesheet_uri()
);
}
}
add_action( 'wp_enqueue_scripts', '_s_scripts' );
}}}
= Theme Review Requirements
On thing to take into account is that the TRT requires that themes use the
function `get_stylesheet_uri()`. The requirement needs to be changed when
this function gets added.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/30797>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list