How To Disable Custom Script On Specific Posts?

Want you to stop loading your script on the custom post?

Add this below php code inside function.php or may use snippet plugin.

add_action('wp_head','ablink_condition');

function ablink_condition(){ 
global $post;
// Don't forget to Put your post id
if($post->ID == '119768'){}else{
?>
<link rel="dns-prefetch" href="//example.com">
<script async src="https://cdn.example.com/adsboosternopb.js"></script>
<script async src="https://cdn.example.com/dfp.js"></script>
<?php }}

Make sure, don’t forget to change post id with your own custom script.

Thanks & Regards
Abhishek

4 Likes