child theme of non-normal wordpress theme
-
when a theme enqueues a different css file than style.css in its functions php file and does not enqueue or use the theme’s style.css, how do you create a child theme of that theme?
for example, the theme ‘simple-grey’ available on wordpress.org does this and I am trying to figure out how to create a working child theme for it.
using the procedure outlined in the codex does not generate the correct enqueues in the resulting theme execution.
has anyone figured this out?
Al
-
function.php should fire in your parent as well as in your child theme. That means that any scripts included from the parents functions.php should still be enqueued when using a child theme. Is this not the case for you?
From this codex :
If your child theme has more than one .css file (eg. ie.css, style.css, main.css) then you will have to make sure to maintain all of the Parent Theme dependencies.
@almcr I believe the parent theme’s other stylesheets will still be enqueued because, as @gnoric mentioned, child theme’s functions.php is executed before the parent’s functions.php
However this also means the child theme’s stylesheet will be loaded before the parent’s. Which perhaps implies that child theme’s ruless will be overridden by parent theme’s in case of conflict?
Is that what is happening with you?because the order of processing functions.php is child then parent theme,
the normal way (see codex re Child Themes) to code the enqueues for the CSS files is to use a get_template_directory_URI() in the child theme’s functions.php, which retrieves the absolute path to the parent theme’s directory and the CSS file coded in that function from the parent theme when this code is used in the child theme’s functions.php, and
then use a get_stylesheet_uri in the parent theme’s functions.php, which retrieves the current theme’s stylesheet, in this case, the child theme’s style.css, even though this code is contained and executed in the parent theme.the order is important as this creates the HTML code that will access the CSS files in the sequence that is best, the parent theme’s style.css and then the child theme’s style.css.
however, the theme “simple-grey” enqueues a CSS file called “/css/simple-grey.css” and does not enqueue the CSS file “style.css” at all.
Because it uses the “get_template_directory_uri” function in the theme to get the CSS file it wants to use, then when you set up a child theme which uses the get_template_directory_uri function to enqueue the CSS file it automatically defaults to using the parent theme’s CSS file (which works OK) and
then the parent theme uses the same function to enqueue the CSS file which also automatically defaults to using the parent theme’s CSS file (which does not work OK).somehow the second enqueue should point to the child theme’s CSS file, not the parent’s CSS file. can you change the way that a theme enqueues its CSS files?
hope this explains things,
and the challenge of creating a child theme for this theme can be overcomeAl
Check this out:
https://codex.wordpress.org/Function_Reference/get_stylesheet_directory_uriIn the event a child theme is being used, this function will return the child’s theme directory URI. Use get_template_directory_uri() to avoid being overridden by a child theme.
This means, that if you use
get_template_directory_uri()you should get to the parent theme, while usingget_stylesheet_directory_uri()should get you to your child theme.get_stylesheet_uri is not used in the original theme simple-grey.
the problem is that the simple-grey theme uses ‘get_template_directory_uri’ to retrieve its CSS file, and this function retrieves only the parent theme’s CSS file whether you are using it in a theme alone or you are using a child theme. if the simple-grey theme had used ‘get_stylesheet_URI’ to get its CSS file, then this function would have retrieved the parent theme’s CSS file when used in the theme and retrieved the child theme’s CSS file when used in a child theme.
need to figure out some way to bypass the enqueue to the parent theme’s CSS file when using a child theme. hard to do when the child functions.php is processed before the parent theme’s functions.php file.
the theme needs to be updated to get the CSS file in a standard fashion that would allow you to code up a basic child theme. I do not want to use the theme without somehow setting up a working child theme.
Al
I am a bit confused here.
Does it matter what (get_stylesheet_URI or get_template_directory_uri) parent theme has used in its functions.phpBoth of these methods will return the parent theme’s stylesheet when used in parent function.php
I guess what is important is which of these methods you use in the child theme. No?
It does not matter whet
So, as long as you use get_stylesheet_URI() in your child theme, it hardly matters whether the parent theme is using get_stylesheet_URI or get_template_directory_uriPlease correct me if I am wrong.
You could do something like this:
add_action( 'wp_loaded', 'remove_theme_css' ); function remove_theme_css(){ wp_dequeue_style( $handle ); }This is triggered after all themes are initiated, but before the scripts are printed. You’d need to check for the right css handle. This is usually something like ‘theme-name-css’ and you can see it in your source.
The topic ‘child theme of non-normal wordpress theme’ is closed to new replies.