Hello @guyinpv ,
To be able to exclude a script, you need to first locate its handler. Detailed step by step instructions are outlined in this thread here – please take a look:
https://wordpress.org/support/topic/how-to-use-sg-optimizers-filters-procedure/
If you need any further assistance, do not hesitate to contact us back.
Regards,
Plamen.M
Tech Support Team
SiteGround.com
Hi, thanks for the response.
These scripts don’t have handlers, I thought that would be fairly clear in the question. The scripts are given by 3rd party and directly placed into post content, they are not being enqueued by WordPress functions, they are inline scripts with a src=”” and no inner code. Think of it like a donate button or something.
<script src="some.3rd.party.script"></script>
It’s not enqueued, there is no handler. But when SGO combines this and moves the code somewhere, it breaks it.
If SGO is only able to exclude scripts with handles, then it should not be processing any script that doesn’t have a handle in the first place! Code like the above needs to be output precisely where it is in the content and cannot be whisked away and combined somewhere into a footer script.
Is there any other way to exclude it?
Hello @guyinpv,
If the code that needs to be excluded contains an URL leading to a third-party script, you should be able to exclude it by using the snippet below:
add_filter( 'sgo_javascript_combine_excluded_external_paths', 'js_combine_exclude_external_script' );
function js_combine_exclude_external_script( $exclude_list ) {
$exclude_list[] = 'script-host.com';
$exclude_list[] = 'script-host-2.com';
return $exclude_list;
}
You need to substitute script-host.com and/or script-host-2.com with the URL or URLs that you need to exclude from the JS combine functionality.
In case you need to exclude an inline script, use the filter below:
add_filter( 'sgo_javascript_combine_excluded_inline_content', 'js_combine_exclude_inline_script' );
function js_combine_exclude_inline_script( $exclude_list ) {
$exclude_list[] = 'first few symbols of inline content script';
return $exclude_list;
}
where you need to substitute “first few symbols of inline content script” with the actual first few symbols of the script.
Best regards,
Daniela Ivanova
SiteGround Support Team