When enqueueing a WordPress child theme stylesheet the correct way the new styles override the parent’s styles.
However, since Divi introduced Builder support for custom post types, a new stylesheet style-cpt.css has been added.
All the styles in this stylesheet (a lot of which unfortunately have !important
after them) are declared after enqueued child styles, so will override any matching ones.
Is there any way of overriding such “custom” stylesheets?
5
Answers
After some experimentation, I found that the following code in functions.php works... (please note, this will enqueue both the standard theme stylesheet as well as Divi's custom post child theme). You can include all the styles you want to override in your own style-cpt.css file in your child theme folder.
I am using this and is working fine:
The "remove_action(…);" solution no longer works as of Divi version 4.10.6 (Sept ’21) as the "et_divi_replace_stylesheet" action was removed.
What I did to solve it was to overwrite line #776 (as of version 4.14.6) from Divi/includes/builder/core.php, so that the function et_builder_should_wrap_styles() always returns false:
Then to make sure I don’t lose this edit when Divi updates, I set up an action to automatically rewrite this line every time a Divi update occurs:
I know it’s technically incorrect to edit a theme’s original file, BUT the "correct" alternative is to overwrite the entire Divi/includes/builder/core.php file in my child theme, which is 7253 lines long! Chances are high that future Divi updates would edit that original file, leaving me without those edits reflected in the child theme version.
very late to the party but I managed to block the CPT styles from divi by prepending the #page-container selector to my Custom CSS in Theme Options, e.g.:
Will override the #et-boc selector
Tested with Divi 6.1.1
I had a similar issue, but the inline generated css stil include the wrappers, so i hade to upgrade @Weekend32 answer:
i remove every cpt related wrappers in the générated inline css, by updating line 6701 in Divi/includes/builder/core.php
So i update the ChildTheme/Function.php update script too: