Exclude script in Pro

Hi,

I´m using a script called jScrollPane and it works great in the frontend, but when I edit in Pro the preview disappear when I make a change and the script is activated.

I´m using this function in functions.php to add the script and I wonder if it is possible to exclude this when editing in Pro as the script isn´t necessary when editing?

 function add_head_script(){

     ?>
      <!-- styles needed by jScrollPane -->
    	<link type="text/css" href="/style/jquery.jscrollpane.css" rel="stylesheet" media="all" />

    	<!-- the mousewheel plugin - optional to provide mousewheel support -->
    	<script type="text/javascript" src="/script/jquery.mousewheel.js"></script>

    	<!-- the jScrollPane script -->
    	<script type="text/javascript" src="/script/jquery.jscrollpane.min.js"></script>
     <?php
     }
    add_action( 'wp_head', 'add_head_script' );

I have tried the code from this post with no luck:

Best regards
Melker

Hi There,

Please try with this code instead:

add_action( 'wp_head', 'x_insert_scripts' );
function x_insert_scripts(){
	$actual_link = "http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
	if ( strpos($actual_link, '#/content/') === false ) {
	 	?>
		<!-- styles needed by jScrollPane -->
    	<link type="text/css" href="/style/jquery.jscrollpane.css" rel="stylesheet" media="all" />
    	<!-- the mousewheel plugin - optional to provide mousewheel support -->
    	<script type="text/javascript" src="/script/jquery.mousewheel.js"></script>
    	<!-- the jScrollPane script -->
    	<script type="text/javascript" src="/script/jquery.jscrollpane.min.js"></script>
	 	<?php
	}
}

For more information, please take a look at these articles:

Hope that helps and thank you for understanding.

I´m afraid that doesn´t work.

Hi,

You can try this code instead.

function themeslug_enqueue_script() {
     wp_enqueue_style( 'my-scrollpane-css', '/style/jquery.jscrollpane.css',false);
     wp_enqueue_script( 'my-mousewheel-js', '/script/jquery.mousewheel.js', false );
     wp_enqueue_script( 'my-scrollpane-js', '/script/jquery.jscrollpane.min.js', false );
}

add_action( 'wp_enqueue_scripts', 'themeslug_enqueue_script' );

By using wp_enqueue_script, the script will be added on the front end only

https://developer.wordpress.org/reference/functions/wp_enqueue_script/

If it still does not work, please provide us your site url so we can take a closer look.

Thanks

Still added in Pro I´m afraid.

Please try our lead developer’s suggestion in this thread response.

Here’s a sample code I’ve tested in my dummy site. You can use wp_enqueue_scripts like Paul showed you.

/*
Load Scripts in Frontend But Not in Cornerstone
*/

function load_scripts_in_frontend_only() {
  $is_cornerstone_preview_frame = did_action( 'cs_before_preview_frame');

  if ( ! $is_cornerstone_preview_frame ) :

?>

<script> // Sample Only
  console.log('Script Loaded in Frontend Only');
</script>

<?php
  endif;
}

add_action( 'wp_head', 'load_scripts_in_frontend_only' );

###Frontend

###Cornerstone

Hope that helps.

Hurray that did the trick!

Thank you so much!

You’re most welcome.

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.