Functions.php to defer scripts if not admin/logged in stops Editor from working

Just wondering how to fix this to not make Pro Editor not work. Here’s what I have:

if (!(is_admin() )) {
	function defer_parsing_of_js ( $url ) {
		if ( FALSE === strpos( $url, '.js' ) ) return $url;
		if ( strpos( $url, 'jquery.js' ) ) return $url;
		if ( strpos( $url, 'x-head.min.js' ) ) return $url;
		return "$url' defer='defer";
	}
	add_filter( 'clean_url', 'defer_parsing_of_js', 11, 1 );
}

Hi @jrhager84,

Thank you for writing in, but sorry we can not provide support for customization. You might want to consider using a caching plugin that offers minification with the option for defer parsing. You may try the Autoptimize plugin. Or any plugins that will help you achieve your Pagespeed’s preferred result.

You can also check out our Performance Tips videos on our Youtube channel.

Cheers!

That code came from your support forum. :man_shrugging:

Hey @jrhager84,

The code we provide serves as a guide only and is to help you in getting started so implementing it and maintaining the code will be out of our support scope and for further maintenance for new possible versions of the theme that may cause the customization to break, you will need to hire a developer.

Thank you for understanding!

Then erase your code on here. Pretty silly to post a ‘solution’ in support for it to not even work (it breaks the editor). Why post a solution that solves nothing? Seems odd.

Terrible practice, imo.

Hey @jrhager84,

Thank you for your feedback but it’s not feasible to remove all the non-working codes here in our forum. As Nabeel said, they only serve as a guide and guides may or may not work. It’s to provide an idea on how to solve a problem but it’s not to be treated as the only solution. Another example of this is our Performance tutorials in our Youtube Channel. They are also guides. We do not support issues arising from customizations including website optimization.

It might be a terrible practice for you but they might give an idea to other developers. And most importantly, custom development including website optimization like your post is outside the scope of our product support.

I hope you understand our position on this.

I don’t. At least you’ve admitted that the ‘solution’ posted by your own staff isn’t a ‘solution’ at all.

I just find that odd. It breaks X theme. You can’t edit any pages with this code active.

The new site forum is a huge step backward, and it seems support is following suit. It’s a shame, really.

Please close this thread.