Title: Create a shortcode
Last modified: February 17, 2021

---

# Create a shortcode

 *  Resolved [roadlink](https://wordpress.org/support/users/roadlink/)
 * (@roadlink)
 * [5 years, 3 months ago](https://wordpress.org/support/topic/create-a-shortcode-3/)
 * 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)

 *  [Kevin Batdorf](https://wordpress.org/support/users/kbat82/)
 * (@kbat82)
 * [5 years, 3 months ago](https://wordpress.org/support/topic/create-a-shortcode-3/#post-14066517)
 * 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](https://wordpress.org/support/users/roadlink/)
 * (@roadlink)
 * [5 years, 3 months ago](https://wordpress.org/support/topic/create-a-shortcode-3/#post-14066753)
 * 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](https://wordpress.org/support/users/roadlink/)
 * (@roadlink)
 * [5 years, 3 months ago](https://wordpress.org/support/topic/create-a-shortcode-3/#post-14066775)
 * 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](https://wordpress.org/support/users/roadlink/)
 * (@roadlink)
 * [5 years, 3 months ago](https://wordpress.org/support/topic/create-a-shortcode-3/#post-14079258)
 * I visited this page. [https://www.metaslider.com/theme-integration/](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](https://wordpress.org/support/users/roadlink/)
 * (@roadlink)
 * [5 years, 3 months ago](https://wordpress.org/support/topic/create-a-shortcode-3/#post-14081276)
 * 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.

 * ![](https://ps.w.org/ml-slider/assets/icon.svg?rev=3568997)
 * [Slider, Gallery, and Carousel by MetaSlider - Image Slider, Video Slider](https://wordpress.org/plugins/ml-slider/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/ml-slider/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/ml-slider/)
 * [Active Topics](https://wordpress.org/support/plugin/ml-slider/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/ml-slider/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/ml-slider/reviews/)

 * 5 replies
 * 2 participants
 * Last reply from: [roadlink](https://wordpress.org/support/users/roadlink/)
 * Last activity: [5 years, 3 months ago](https://wordpress.org/support/topic/create-a-shortcode-3/#post-14081276)
 * Status: resolved