We're merging with GenerateBlocks! Learn more here.

[Resolved] Change arrows, dots and autoplay settings in specific wpsp list

Please login to receive premium support.

Support for the free plugin can be found here.

Home Forums Pro Support Change arrows, dots and autoplay settings in specific wpsp list

Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • #24156
    Georgios
    Participant

    Dear Great Support Team of WPSP, GP and GB,

    Is there any way to set different settings regarding the display of arrows, dots (hidden or not) and autoplay (like speed etc), in different wpsp lists in my website. For instance, I want to have one wpsp list with “card carousel” format with arrows only and no-autoplay and another one with “card carousel” format with dots only and autoplay.

    For now I have used the below code snippet for setting the autoplay:

    add_filter( ‘wpsp_carousel_args’, function( $args ) {
    $args[‘autoplay’] = true;
    $args[‘autoplaySpeed’] = 3000;
    return $args;
    } );

    and the below code snippet for disabling arrows:

    add_filter( ‘wpsp_carousel_args’, function( $args ) {
    $args[‘arrows’] = false;
    return $args;
    } );

    But the above snippets effect all my lists in my website page (I want only to specific, maybe with an ID or sth else).

    Thanks in advance for your help,

    Best regards

    Georgios

    #24195
    elvin
    Moderator

    Hi,

    You can modify your code to add conditions.

    Example:

    add_filter( 'wpsp_carousel_args', function( $args, $settings ) {
        if ( 123 === (int) $settings['list_id'] ) {
            $args['autoplay'] = true;
            $args['autoplaySpeed'] = 3000;
        }
        return $args;
    } );

    And this:

    add_filter( 'wpsp_carousel_args', function( $args, $settings ) {
        if ( 123 === (int) $settings['list_id'] ) {
            $args['arrows'] = false;
        }
        return $args;
    } );

    You then replace 123 to your WPSP list id.

    #24201
    Georgios
    Participant

    Hello Elvin,

    Thanks for your response!

    I entered the snippet you provided for disabling arrows (replacing 123 with 399 which is my id for wpsp list):

    add_filter( 'wpsp_carousel_args', function( $args, $settings ) {
        if ( 399 === (int) $settings['list_id'] ) {
            $args['arrows'] = false;
        }
        return $args;
    } );

    I am using child theme of GPP, and I entered the above code at the functions.php (of the GP child theme). However, an error is returned, which is dercribed below:

    Your PHP code changes were rolled back due to an error on line 28 of file wp-content/themes/generatepress-child/functions.php. Please fix and try saving again.

    Uncaught ArgumentCountError: Too few arguments to function {closure}(), 1 passed in wp-includes/class-wp-hook.php on line 289 and exactly 2 expected in wp-content/themes/generatepress-child/functions.php:28
    Stack trace:
    #0 wp-includes/class-wp-hook.php(289): {closure}()
    #1 wp-includes/plugin.php(212): WP_Hook->apply_filters()
    #2 wp-content/plugins/wp-show-posts-pro/modules/carousel/carousel.php(104): apply_filters()
    #3 wp-includes/class-wp-hook.php(287): wpsp_pro_enqueue_carousel()
    #4 wp-includes/class-wp-hook.php(311): WP_Hook->apply_filters()
    #5 /var/www

    and the whole page where the wpsp list exists, breaks!

    Furthermore, I tried to inject the above code using the “Code Snippets” plugin, but the result was the same again.

    Is there sth that I am doing wrong?

    Thanks again in advance for your help!

    Best regards,

    Georgios

    #24205
    elvin
    Moderator

    Ah right my bad.

    Try this instead. (removed $settings as wpsp_carousel_args() only accepts $args)

    add_filter( 'wpsp_carousel_args', function( $args ) {
        if ( 399 === (int) $settings['list_id'] ) {
            $args['arrows'] = false;
        }
        return $args;
    } );

    Let us know.

    #24225
    Georgios
    Participant

    Hi Elvin,

    Unfortunately, nothing happened even with the updated version of code you provided me (without $settings as argument at the function wpsp_carousel_args()).

    The only good thing is that now, there is no any error message at the editor.

    Any other idea of how this can be achieved?

    Regards,

    Georgios

    #24232
    elvin
    Moderator

    Try this:

    add_filter( 'wpsp_carousel_args', function( $args , $settings ) {
        if ( 399 === (int) $settings['list_id'] ) {
            $args['arrows'] = 'false';
        }
        return $args;
    }, 10, 2 );

    Changes: I’ve added in back the $settings and fixed the filter args to indicate to the filter how many args its supposed to take (2).

    I’ve also changed false to 'false' so the JS library it uses (slick) reads it as a text literal string false as not making it a string will imply its a variable or a function.

    This should work now. I’ve made sure I tested this as opposed to the previous ones. (my bad, WordPress 5.6 had us testing things)

    Let us know. 🙂

    #24244
    Georgios
    Participant

    Awesome! Now everything works fine!

    Thank you very much Elvin for the support and the detailed description of the modifications!

    Best regards,

    Georgios

    #24246
    elvin
    Moderator

    Thank you very much Elvin for the support and the detailed description of the modifications!

    No problem. Always glad to impart some knowledge and be of any help. 😀

Viewing 8 posts - 1 through 8 (of 8 total)
  • You must be logged in to reply to this topic.