X - wp_enqueue_script script only on front

Hi,

I added a custom JS file on the front. It tweaks some elements and the way sections are displayed.
Some sections, according to their classes, are hidden. Thus, I don’t wait this script to be included when I use cornerstone.

Right now, I’m using this function:

function custom_scripts()
{
wp_register_script(‘custom-script’, get_stylesheet_directory_uri() . ‘/custom.js’, array(), false, true);
if( !is_user_logged_in() ) {
wp_enqueue_script(‘custom-script’);
}else {
wp_dequeue_script(‘custom-script’);
}
}
add_action(‘wp_enqueue_scripts’, ‘custom_scripts’, 99);

I don’t like it too much because the user have to be disconnected to see the website correctly.
I’m looking for another way to do it. Something like !is_cornerstone()

I can’t play with REQUEST_URI because it’s acting like a frame. The URI is the same than the one on the front, even though it is /pro/ in the URL.

Hi @lijecreative,

Thanks for reaching out.

Try replacing the line

if( !is_user_logged_in() ) {

with this line

if ( ! isset( $_POST['cs_preview_state'] ) || ! $_POST['cs_preview_state'] || 'off' === $_POST['cs_preview_state'] ) {

Hope this helps.

Perfect, thanks!

Glad we were able to help :slight_smile:

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