• Resolved chrimbus

    (@chrimbus)


    Hi, I have some markup in a page.php template file. I am wondering if it’s possible to install this plugin but target a class in the html to create a slider from there?

    Example:
    <div class=”myslider slick-class-target”>



    </div>

Viewing 1 replies (of 1 total)
  • Plugin Author Philipp Bammes

    (@tyrannous)

    Hi @chrimbus,
    you can enqueue Slick’s assets on any template you want. To do this, follow the steps described in Is it possible to use slick’s JS and CSS independently?.

    Then, add the following code to your (child theme’s) function.php to enqueue an inline initialization script for your custom class whenever Slick’s assets are enqueued:

    add_action( 'wp_enqueue_scripts', function() {
    	wp_add_inline_script( 'slick-slider-core', file_get_contents( get_stylesheet_directory() . '/assets/js/slick-slider-custom.js' ) );
    }, 11 );

    Create the file slick-slider-custom.js in your (child) theme’s assets/js/ folder and paste the following code:

    jQuery( document ).ready( function() {
    	jQuery( '.slick-class-target' ).slick();
    } );

    That’s all.

    Note: You may have to adjust the location of the JavaScript file according to your (child) theme file structure.

    I hope this works for you. If it does, please set this thread’s status to resolved. Thanks.

Viewing 1 replies (of 1 total)
  • The topic ‘Is it possible to target a class vs using shortcode?’ is closed to new replies.