Child theme CSS doesn't work

Hi there !

I have created a Child Theme to customise style.css et function.php files.

I noticed that the css code in style.css does not work.
However, the same code in “Customize > addional CSS” works.
Php codes works in function.php, it only concern css in style.css

I also tried to put these codes in the parent theme files and it’s the same, the CSS is not applied, even with the !important rule…

Do you know what could be the cause of this?

Please make sure that the generated child theme loads its style.css file correctly, it should be loaded after the parent one (then the child theme’s styles will have a higher priority). You can check this in the functions.php file of the child theme.

1 Like

In fact child’s theme are loaded before the parent for function.php, the “price field optionnal” is applied well.
Capture d’écran 2022-10-18 à 21.51.01

This is not the case for style.css :woozy_face:

But anyway, as long as I can modify function.php and css with the wp embedded editor it’s not a big deal.
I would like to know if this is normal or if it is a malfunction / bad installation ?

Please try changing this line:

$parent_style = 'parent-style';

to:

$parent_style = 'hivetheme-parent-frontend';

And remove the first wp_enqueue_style, it’s not required because the parent theme’s style is loaded by HivePress automatically.

1 Like

Thanks ihor.

So these modifications works because the “price field optionnal” code still works with modifications.

But after the update, we can see that the layout, fonts, and colors are changed :

Before the code updated :

After :

I think I’ll stay with the older Function.php codes generated by the Child Theme Wizard Plugin and put CSS codes in the embedded wp editor. I don’t want to take you so much time on it, It works for Function and I can apply custom CSS in another place so…
If you tell me that there is no danger or risk of conflict / something else I can stay like that.

Thank you,
Julien

Sure, you can keep CSS snippets using a third-party plugin or directly in Appearance/Customize/Additional CSS, but I recommend some solution for creating weekly website backups because in this case all the customizations are stored in the database. A child theme is required only if you want to override specific HTML parts of the parent theme, by copying them to the child theme folder.

1 Like

In my case my host provider makes websites backups daily, if is what you mean.

I thought that a child theme was mainly used to customize a site without risk of losing changes when updating the theme or plugin?

If I make some customizations in the style.css parent’s file, I’ll certainly lose them when an updates is released ?

I did some research and I couldn’t find why in my child theme files the function.php codes works while the .css style ones don’t.

The only requirement is to avoid editing the parent theme files directly. You can keep custom CSS in Appearance/Additional CSS or using third-party plugins, a child theme can be also used for this but it’s not required, it’s needed only if you want to override specific HTML template parts.

1 Like

Hi ihor.

Understood ! Thank you for your help on this.
Last question to ensure my understanding > Is it well the code brought to function.php which allows to bypass the html ?

Please share more details about this issue, do you mean some specific code snippets in functions.php? Make sure that you don’t edit the parent theme’s functions.php file directly (or any of its files) because any direct changes are reset on update.

I was wondering if this is in funtion.php that we “override specific HTML template parts” in child file

There are 4 ways to customize templates in HivePress:

  • Using custom code snippets for hivepress/v1/templates/{template_name} hooks. You can keep them using Code Snippets plugin (without a child theme) or in the child theme’s functions.php file.

  • By copying specific template parts from hivepress/templates to the child theme’s hivepress subfolder.

  • By adding templates that override the default ones completely in HivePress/Templates (this doesn’t require code customizations)

  • Using CSS snippets only (if styling changes are enough), you can keep them in Appearance/Cusotmize/Additional CSS without a child theme, or in the child theme’s style.css file.

So a child theme may not be required depending on the changes.

1 Like

Hi ihor,

Your help and time are very appreciated thank you.

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.