• Resolved roadlink

    (@roadlink)


    Hello,
    I was using other slider plugin and set a shortcode like this.

    add_shortcode( 'sliderbydevice', function() {
    if ( wp_is_mobile() ) {
    if ( function_exists( 'soliloquy' ) ) { soliloquy( '390653' ); }
    } else {	
    if ( function_exists( 'soliloquy' ) ) { soliloquy( '390651' ); }
    }});

    I tried same for metaslider but it doesn’t work.

    add_shortcode( 'sliderbydevice', function() {
    if ( wp_is_mobile() ) {
    echo do_shortcode('[metaslider id="46112"]');
    } else {	
    echo do_shortcode('[metaslider id="2703"]');
    }});

    Do you have a php code instead of shortcode?

Viewing 5 replies - 1 through 5 (of 5 total)
  • Hi,

    I don’t know what the shortcode sliderbydevice is. Maybe that was from the other plugin too? Try it without that part.

    if ( wp_is_mobile() ) {
      echo do_shortcode('[metaslider id="46112"]');
    } else {	
      echo do_shortcode('[metaslider id="2703"]');
    }
    Thread Starter roadlink

    (@roadlink)

    I created it via code snippet.
    So I can put that shortcode in the page buildier.

    I am not sure hopw to add php without shortcode in to page?
    Soliloguy slider offers both php and shortcode to print slider.
    Thus first code is working. But yours don’t ??

    Thread Starter roadlink

    (@roadlink)

    I tried this one too but didn’t work.

    add_shortcode( 'sliderbydevice', function() {
    if ( wp_is_mobile() ) : ?>
    [metaslider id="46112"]
    <?php else : ?>
    [metaslider id="2703"]
    <?php endif;
    }
    );

    Then put [sliderbydevice] as a shortcode to theme.

    Thread Starter roadlink

    (@roadlink)

    I visited this page. https://www.metaslider.com/theme-integration/

    `if (is_home() || is_front_page()) : echo do_shortcode(“”); // replace 123 with your slideshow ID elseif ( $header_image ) :”
    It mentions 123 but there is no 123 there.

    Thread Starter roadlink

    (@roadlink)

    Ok, Solved finally.

    This is using wordpress is_mobile funtion.

    Add this with code snipper plugin

    function lookifmobile(){
    if ( wp_is_mobile() ) {
    echo do_shortcode('[metaslider id="46112"]');
    }
    else {
    echo do_shortcode('[metaslider id="2703"]');
    }
    }
    add_shortcode( 'sliderbydevice', 'lookifmobile' );

    Add this shortcode to your theme
    [sliderbydevice]

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Create a shortcode’ is closed to new replies.