• Resolved thomastthai

    (@thomastthai)


    Frank, thank you for the amount of support you dedicate to your customers. You are very active and timely with providing support. You have this calmness about you; no matter how simple or complicated the questions are. It’s an unprecedented level of support. However you manage to find the time to do it, kudos and thank you!

    I finally got Autoptimize to work with BuddyBoss Social Marketplace theme and many other plugins when I switched from Apache to Nginx. I still don’t know why the change worked. There are a few quirks still but I’m working through them.

    BuddyBoss Social Marketplace uses their OneSocial theme. That theme has a OneSocial Child theme. I made modifications to the functions.php file and it has CSS stuff in there for the child theme. When I have Autoptimize CSS Options checked, the CSS changes in the child theme isn’t used. Would you know what could cause this? Deleting the Autoptimize cache didn’t help.

    I noticed in the WordPress Admin Panel / Appearance / Customize, the child CSS changes appear as they should with Autoptimize CSS Options checked.

Viewing 15 replies - 1 through 15 (of 15 total)
  • Plugin Author Optimizing Matters

    (@optimizingmatters)

    might be due to AO grouping CSS per media-type, cfr. this blogpost. can you share the URL @thomastthai ?

    Thread Starter thomastthai

    (@thomastthai)

    It’s on a pre-launch server and is password protected. I can send you a URL in private. Would would you prefer I send that to you? I read the CFR you cited and it is very plausible that is what is happening with my child theme.

    Plugin Author Optimizing Matters

    (@optimizingmatters)

    sure, you can contact me on futtta-at-gmail-dot-com ??

    Plugin Author Optimizing Matters

    (@optimizingmatters)

    OK, had a look. If you consider this as the main CSS-files;

    <link rel='stylesheet' id='onesocial-main-global-css'  href='https://gooroogle.com/wp-content/themes/onesocial/css-compressed/main-global.css?ver=1.3.0' type='text/css' media='all' />
    <link rel='stylesheet' id='onesocial-main-desktop-css'  href='https://gooroogle.com/wp-content/themes/onesocial/css-compressed/main-desktop.css?ver=1.3.0' type='text/css' media='screen and (min-width: 481px)' />
    <link rel='stylesheet' id='onesocial-main-mobile-css'  href='https://gooroogle.com/wp-content/themes/onesocial/css-compressed/main-mobile.css?ver=1.3.0' type='text/css' media='screen and (max-width: 480px)' />
    <link rel='stylesheet' id='onesocial-child-custom-css'  href='https://gooroogle.com/wp-content/themes/onesocial-child/css/custom.css?ver=4.7.5' type='text/css' media='all' />
    

    As AO honours the media-types, you get this;

    <link type="text/css" media="all" href="https://gooroogle.com/wp-content/cache/autoptimize/css/autoptimize_0b1c15fee12af2d032579e97426a34b3.css" rel="stylesheet" />
    <link type="text/css" media="screen and (min-width: 481px)" href="https://gooroogle.com/wp-content/cache/autoptimize/css/autoptimize_583858f486646b934ceccb46e8ffc2ab.css" rel="stylesheet" />
    <link type="text/css" media="screen and (max-width: 480px)" href="https://gooroogle.com/wp-content/cache/autoptimize/css/autoptimize_f23b1def71f6b01adcd4fea67d1508d0.css" rel="stylesheet" />
    

    where the first one (media=all) has your child CSS as the very first CSS-files extracted from the HTML are of that media type.

    Solution; try excluding onesocial-child/css/custom.css from AO optimization (easy) OR split your child theme CSS up in 2 CSS files and enqueue separately using the same media-types (screen and (max-width: 480px) and screen and (min-width: 481px) as the parent theme.

    frank

    Thread Starter thomastthai

    (@thomastthai)

    Thank you for the follow up. The CSS file you cited wasn’t where I made the changes in the child theme. Since the OnceSocial theme hard coded some CSS so they can use variables in the CSS, I had to make my modifications and put it in functions.php for my child theme.

    I emailed you a copy of functions.php. Do a search for THAI in that file and you will see where I made the change.

    Plugin Author Optimizing Matters

    (@optimizingmatters)

    same problem; your inline CSS is aggregate in the media=”all” stylesheet which gets loaded first, so exclude it from optimziation and all should be fine ??

    Thread Starter thomastthai

    (@thomastthai)

    Thank you. I know how to exclude a CSS file. How would I exclude this inline CSS code in functions.php?

    Plugin Author Optimizing Matters

    (@optimizingmatters)

    as per the FAQ; identify a (semi-)unique string in the inline CSS and use that ??

    Thread Starter thomastthai

    (@thomastthai)

    I appreciate the gentle reminder to re-read the FAQ while providing the answer. Thank you kindly.

    Thread Starter thomastthai

    (@thomastthai)

    I read the FAQ again and added the unique string to the CSS exception field. It still didn’t use the style from the child theme while having CSS Options checked.

    if you want to exclude inline code, you’ll have to find a specific, unique string in that block of code and add that to the exclusion list. Example: to exclude <script>funky_data=’Won\’t you take me to, Funky Town'</script>, the identifier is “funky_data”.

    The code snippet below from functions.php is a copy and paste of the same section from the parent theme with minor changes in the bold lines. Since the are almost identical, it was hard to find a unique string that would cause the exception in the parent but not the child and still be upgrade safe. I tried two approaches to make things unique from the parent theme.

    First I deleted the line “/* Accent color */” in functions.php. This would leave only the parent theme to have the word Accent for that section of code. My thinking is Autoptimize would remove or not use that whole <style> </style> section from the parent theme. I put “Accent” in the field “Exclude CSS from Autoptimize:” so it looks like this:

    admin-bar.min.css, dashicons.min.css, Accent

    After saving, clearing the cache and doing a page refrest, the child theme inline CSS was still not used.

    Next I tried to add this whole string (not knowing if I can have spaces in a string) in the Exclude CSS field since that line only appears in the parent theme and has been changed in the child theme:

    <blockquote>box-shadow: 0 -1px 0 <?php echo $accent_color; ?> inset; </blockquote>

    That didn’t work. Child theme inline CSS is still not used.

    <blockquote>if ( !function_exists( 'boss_generate_option_css' ) ) {
    
    	function boss_generate_option_css() {
    
    		$accent_color	 = onesocial_get_option( 'accent_color' );
    		?>
    
    		<style>
    
    			<strong>/* Accent color */</strong>
    			a { color: <?php echo $accent_color; ?>; }
                .widget_mc4wp_form_widget form p input[type="submit"], .widget.widget_newsletterwidget form p input[type="submit"],
                .footer-widget #switch-mode input[type="submit"],
                .woocommerce #respond input#submit, 
                .woocommerce a.button, 
                .woocommerce button.button, 
                .woocommerce input.button,
    ...
    
    			.header-button.underlined {
    				<strong>/* THAI: PARENT THEME- box-shadow: 0 -1px 0 <?php echo $accent_color; ?> inset; */
    				box-shadow: 0 0 0 <?php echo $accent_color; ?> inset;</strong>
    			}
    
    ...
    
    		</style><?php
    	}
    
    	/* Add Action */
    	add_action( 'wp_head', 'boss_generate_option_css', 99 );
    }</blockquote>
    Plugin Author Optimizing Matters

    (@optimizingmatters)

    you took the opposite approach of what would have worked ??

    as you “own” the inline CSS, you can put whatever string in there, e.g.
    /* dontoptimizeme */

    in which case adding dontoptimizeme to the CSS exclusions should work ??

    Thread Starter thomastthai

    (@thomastthai)

    Good news, child theme CSS is now working. Here is what I fixed. After re-reading what I wrote above, I realized I should be telling Autoptimized to “skip code from being aggregated and minimized” in the CHILD theme! I was trying to tell it to skip the code in the parent theme using “Accent” as the unique identifier. In functions.php of the child theme, I added this line to cause this section to be unique from the parent theme:

                   <style>
                    /* EXCLUDE_ME_PLEASE: Place marker to exclude from processing by Autoptimize */

    I then added EXCLUDE_ME_PLEASE to the field “Exclude CSS from Autoptimize.”

    That worked to get some of that inline style to work from the child theme. There were still borders that shouldn’t be there. I re-read Frank’s other comment and looked at the file:

    onesocial-child/css/custom.css

    and did see that I made some changes there with regard to the borders! I added that to the field to exclude.

    Now I have the style I wanted with Autoptimize enabled.

    Thank you Frank!

    Plugin Author Optimizing Matters

    (@optimizingmatters)

    great work @thomastthai ! ??

    Thread Starter thomastthai

    (@thomastthai)

    Frank, I’m going to follow up with BuddyBoss and give them feedback. How would you recommend they handle the inline CSS to make it friendly with Autoptimize (so others wouldn’t have to do the exclude?

    As far as:

    <link rel=’stylesheet’ id=’onesocial-main-global-css’ href=’https://gooroogle.com/wp-content/themes/onesocial/css-compressed/main-global.css?ver=1.3.0&#8242; type=’text/css’ media=’all’ />
    <link rel=’stylesheet’ id=’onesocial-main-desktop-css’ href=’https://gooroogle.com/wp-content/themes/onesocial/css-compressed/main-desktop.css?ver=1.3.0&#8242; type=’text/css’ media=’screen and (min-width: 481px)’ />
    <link rel=’stylesheet’ id=’onesocial-main-mobile-css’ href=’https://gooroogle.com/wp-content/themes/onesocial/css-compressed/main-mobile.css?ver=1.3.0&#8242; type=’text/css’ media=’screen and (max-width: 480px)’ />
    <link rel=’stylesheet’ id=’onesocial-child-custom-css’ href=’https://gooroogle.com/wp-content/themes/onesocial-child/css/custom.css?ver=4.7.5&#8242; type=’text/css’ media=’all’ />

    It looks as though they did their part correctly. I was the one who didn’t optimize the custom.css file for Autoptimize correctly.

    Plugin Author Optimizing Matters

    (@optimizingmatters)

    no one-size fits all solution, as it depends on interaction between theme (onesocial) and plugin (buddyboss). only when both enqueue CSS in the same way (with the same media-attrib) will it work out of the box i’m afraid, but the buddyboss guys&girls can’t cater for every theme out there, so ..

    the way the onesocial-devs separate the CSS for different screensizes is correct, but it’s not common. would have been easier if they would have one CSS-file for media=all with the mediaqueries inside.

Viewing 15 replies - 1 through 15 (of 15 total)
  • The topic ‘Child Theme Functions.php CSS Not Used’ is closed to new replies.