Below, you’ll find a detailed guide on how to add the Gallery Shortcodes to your WordPress website, including their parameters, examples, and PHP function code. Additionally, we’ll assist you with common issues that might cause the Gallery Plugin shortcodes not to show or not to work correctly.
Before starting, here is an overview of the Gallery Plugin and the shortcodes it provides:

"Gallery – Photo Albums Plugin is a user-friendly WordPress plugin that enables you to effortlessly create, manage, and showcase stunning photo albums on your website. Simplify your media gallery management with Easy Media Gallery."
- [easy-media]
- [easymedia-gallery]
Gallery [easy-media] Shortcode
The Easy Media Gallery shortcode allows you to create a media gallery with various media types including single images, videos, audios, and multiple images. It supports pagination and custom alignment.
Shortcode: [easy-media]
Parameters
Here is a list of all possible easy-media shortcode parameters and attributes:
cat
– specifies the category ID of the mediacol
– determines the number of columns in the galleryalign
– controls the alignment of the media within the gallerymed
– defines the ID of the specific media to be displayed
Examples and Usage
Basic Example – Display media from a specific category with alignment and column settings
[easy-media cat="2" align="center" col="3"]
In this example, the shortcode will display all media items from the category with the ID of 2. The media items will be aligned in the center and displayed in 3 columns.
Advanced Examples
Display specific media items in a customized layout
[easy-media med="1,2,3" align="left" col="2"]
In this advanced example, the shortcode will display the media items with the IDs 1, 2, and 3. The media items will be aligned to the left and displayed in 2 columns.
Display media from a specific category with customized layout and pagination
[easy-media cat="2" align="right" col="4" paged="2"]
In this advanced example, the shortcode will display media items from the category with the ID of 2. The media items will be aligned to the right and displayed in 4 columns. The ‘paged’ parameter is set to 2, meaning the second page of media items will be displayed.
PHP Function Code
In case you have difficulties debugging what causing issues with [easy-media]
shortcode, check below the related PHP functions code.
Shortcode line:
add_shortcode( 'easy-media', 'easy_media_shortcode' );
Shortcode PHP function:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 | function easy_media_shortcode( $atts ) { if ( easy_get_option( 'easymedia_disen_plug' ) == '1' ) { extract( shortcode_atts( array ( 'cat' => -1, 'col' => '' , 'align' => '' , 'med' => -1 ), $atts ) ); ob_start(); $paged = ( get_query_var( 'paged' ) ) ? get_query_var( 'paged' ) : 1; // for pagination if ( $med <= '0' && $cat > '0' ) { $emgargs = array ( 'post_type' => 'easymediagallery' , 'showposts' => -1, 'posts_per_page' => -1, 'orderby' => 'menu_order' , 'order' => 'ASC' , 'tax_query' => array ( array ( 'taxonomy' => 'emediagallery' , 'terms' => $cat , 'field' => 'term_id' , ) ), ); } else if ( $cat <= '0' && $med > '0' ) { $fnlid = explode ( "," , $med ); $emgargs = array ( 'post__in' => $fnlid , 'post_type' => 'easymediagallery' , 'posts_per_page' => -1, 'order' => 'ASC' , 'orderby' => 'menu_order' , 'paged' => $paged ); } // Get media options $deff_img_limit = easy_get_option( 'easymedia_img_size_limit' ); // get the default image size limit $theopt = easy_get_option( 'easymedia_frm_size' ); $imwidth = stripslashes ( $theopt [ 'width' ] ); $imheight = stripslashes ( $theopt [ 'height' ] ); // Custom columns filter $num_cols = easymedia_sc_handler( $col , '0' ); // Custom Align filter $cus_align = easymedia_sc_handler( $align , '1' ); // Load Media $emg_query = new WP_Query( $emgargs ); if ( $emg_query ->have_posts() ): echo '<div class="pfwrpr"><div id="alignstyle" class="easymedia_' . $cus_align . '">' ; for ( $i =1 ; $i <= $num_cols ; $i ++ ) : echo '<div id="col-' . $i . '" class="thecol">' ; $counter = $num_cols + 1 - $i ; while ( $emg_query ->have_posts() ) : $emg_query ->the_post(); $image = get_post_meta( get_the_id(), 'easmedia_metabox_img' , true ); $mediattl = get_post_meta( get_the_id(), 'easmedia_metabox_title' , true ); $mediattl = esc_html(esc_js( $mediattl )); $mediattl = stripslashes ( $mediattl ); $mediatype = get_post_meta( get_the_id(), 'easmedia_metabox_media_type' , true ); $isvidsize = get_post_meta( get_the_id(), 'easmedia_metabox_media_video_size' , true ); $isresize = get_post_meta( get_the_id(), 'easmedia_metabox_media_gallery_opt1' , true ); $isresize1 = get_post_meta( get_the_id(), 'easmedia_metabox_media_image_opt1' , true ); $usegalleryinfo = get_post_meta( get_the_id(), 'easmedia_metabox_media_gallery_opt2' , true ); $thepostid = get_the_id(); $is_gallery = '' ; if ( $image == '' ) { $image = plugins_url( 'images/no-image-available.jpg' , __FILE__ ) ; } else { $image = $image ; $globalsize = wp_get_attachment_image_src( emg_get_attachment_id_from_src( $image ), 'full' ); } if ( $mediatype == 'Video' && $isvidsize == 'off' ) { $cusvidw = get_post_meta( get_the_id(), 'easmedia_metabox_media_video_size_vidw' , true ); $cusvidh = get_post_meta( get_the_id(), 'easmedia_metabox_media_video_size_vidh' , true ); $therell = "easymedia[" . $cusvidw . " " . $cusvidh . "]" ; } elseif ( $mediatype == 'Video' && $isvidsize == 'on' ) { $getarry = easy_get_option( 'easymedia_vid_size' ); $defvidw = stripslashes ( $getarry [ 'width' ] ); $defvidh = stripslashes ( $getarry [ 'height' ] ); $therell = "easymedia[" . $defvidw . " " . $defvidh . "]" ; } else { $therell = "easymedia" ; } switch ( $mediatype ) { case 'Single Image' : if ( basename ( $image ) == 'no-image-available.jpg' ) { $medialink = $image ; } else { $attid = wp_get_attachment_image_src( emg_get_attachment_id_from_src( $image ), 'full' ); $medialink = easymedia_imgresize( $attid [0], $deff_img_limit , $isresize1 , $attid [1], $attid [2] ); $medialink = explode ( "," , $medialink ); $medialink = $medialink [0]; } $therell = "easymedia" ; break ; case 'Video' : $medialink = get_post_meta( get_the_id(), 'easmedia_metabox_media_video' , true ); break ; case 'Audio' : $medialink = get_post_meta( get_the_id(), 'easmedia_metabox_media_audio' , true ); $therell = "easymedia" ; break ; case 'Multiple Images (Slider)' : $therell = "easymedia[" .emgRandomString(6). "]" ; $images = get_post_meta( get_the_id(), 'easmedia_metabox_media_gallery' , true ); $is_gallery = $images ; ob_start(); if ( is_array ( $images ) ) { $ig = 0; echo '<div id="easymedia_gallerycontainer-' .emgRandomString(6). '" style="display:none">' ; foreach ( $images as $img_id ) { //Changelog version 1.3.10 => Set 1st Image Gallery if ( $ig ++ == 0) { $img = wp_get_attachment_image_src( $img_id , 'full' ); $frstimg = $img_id ; $medialink = easymedia_imgresize( $img [0], $deff_img_limit , $isresize , $img [1], $img [2] ); $medialink = explode ( "," , $medialink ); $medialink = $medialink [0]; $image = $medialink ; } $img = wp_get_attachment_image_src( $img_id , 'full' ); $img_url = easymedia_imgresize( $img [0], $deff_img_limit , $isresize , $img [1], $img [2] ); $img_url = explode ( "," , $img_url ); ?> <a class = "<?php echo $thepostid; ?>-<?php echo $img_id; ?>" href= "<?php echo $img_url[0]; ?>" rel= "<?php echo $therell; ?>" ></a> <?php $imgcount = $ig ; } echo '</div>' ; } else { echo '<div style="display:none"></div>' ; } $galle = ob_get_clean(); if ( $imgcount <= 1) { $sorn = 'image' ;} else { $sorn = 'images' ;} break ; } if ( $counter % $num_cols == 0 ) : $curimgnmane = basename ( $image ); if ( $curimgnmane == 'no-image-available.jpg' || $image == '' ) { if ( is_array ( $is_gallery ) ) { $image = reset( $is_gallery ); $image = wp_get_attachment_image_src( $image , 'full' ); $image = easymedia_resizer( $image , $globalsize [1], $globalsize [2], $imwidth , $imheight , true ); } } else { $globalsize = wp_get_attachment_image_src( emg_get_attachment_id_from_src( $image ), 'full' ); $image = easymedia_resizer( $image , $globalsize [1], $globalsize [2], $imwidth , $imheight , true ); } if ( $mediatype == 'Multiple Images (Slider)' ){ $addbadge = '<span class="emg-badges"><span class="icount">' . $imgcount . '</span><span class="imgtg">' . $sorn . '</span></span>' ; } else { $addbadge = '' ;} if ( easy_get_option( 'easymedia_disen_hovstyle' ) == '1' ) { ?> <div style= "width:<?php echo $imwidth; ?>px; height:<?php echo $imheight; ?>px;" class = "view da-thumbs" ><?php echo $addbadge ; ?><div class = "iehand" ><img width= "<?php echo $imwidth; ?>" height= "<?php echo $imheight; ?>" src= "<?php echo $image; ?>" alt= "<?php echo $mediattl; ?>" /><a class = "<?php if ( $mediatype == 'Multiple Images (Slider)' && $usegalleryinfo == 'on' ) { echo $thepostid.'-'.$frstimg; } else { echo $thepostid; } ?>" rel= "<?php echo $therell; ?>" href= "<?php echo $medialink; ?>" ><article class = "da-animate da-slideFromRight" ><p <?php if ( $mediattl == '' ) { echo 'style="display:none !important;"' ; } ?> class = "emgfittext" ><?php echo $mediattl ; ?></p><div class = "forspan" ><span class = "zoom" ></span></div></article></a></div></div> <?php } elseif ( easy_get_option( 'easymedia_disen_hovstyle' ) == '' ) { ?> <div class = "view da-thumbs" ><?php echo $addbadge ; ?><div class = "iehand" ><a class = "<?php if ( $mediatype == 'Multiple Images (Slider)' && $usegalleryinfo == 'on' ) { echo $thepostid.'-'.$frstimg; } else { echo $thepostid; } ?>" rel= "<?php echo $therell; ?>" href= "<?php echo $medialink; ?>" ><img width= "<?php echo $imwidth; ?>" height= "<?php echo $imheight; ?>" src= "<?php echo $image; ?>" /></a></div></div> <?php } endif ; $counter ++; //Changelog version 1.3.10 => Generate Image Gallery if ( $mediatype == 'Multiple Images (Slider)' ) { echo $galle ; } endwhile ; echo '</div>' ; //closes the column div endfor ; else : echo '<div class="pfwrpr"><div class="alignstyle"><div class="thecol">' ; ?> <div class = "view" ><img src= "<?php echo plugins_url('images/ajax-loader.gif' , __FILE__); ?>" width= "32" height= "32" /></div> <?php endif ; wp_reset_postdata(); echo '<div style="clear:both;"></div>' ; echo '</div>' ; // @since 1.3.75 if ( emg_get_aff_option( 'emg_affiliate_info' , 'emg_aff_id' , '' ) ) { echo '<span class="emg-aff-link">Powered by <a href="https://secure.ghozylab.com/demo/?ref=' .emg_get_aff_option( 'emg_affiliate_info' , 'emg_aff_id' , '' ). '&goto=emg" target="_blank">Easy Media Gallery Plugin</a></span>' ; } echo '</div>' ; // JS emg_put_script(); // Dinamic CSS echo '<style>/*Dynamic CSS - By GhozyLab*/' ; echo emg_dynamic_css_generator(); echo '</style>' ; $content = ob_get_clean(); return $content ; } else { ob_start(); echo '<div style="display: none;"></div>' ; $content = ob_get_clean(); return $content ; } } |
Code file location:
easy-media-gallery/easy-media-gallery/includes/shortcode.php
Gallery [easymedia-gallery] Shortcode
The Easy Media Gallery shortcode is used to generate a media gallery on your WordPress site. It extracts the media and size attributes from the shortcode and creates a gallery with pagination. The PHP function ‘easy_media_gnl_shortcode’ linked to this shortcode, fetches media files, resizes images, and generates dynamic CSS for the gallery layout. It also includes an affiliate link if configured. This shortcode makes it easy to create a visually appealing media gallery with customization options. It’s a powerful tool for enhancing your site’s media display.
Shortcode: [easymedia-gallery]
Parameters
Here is a list of all possible easymedia-gallery shortcode parameters and attributes:
med
– Specifies the media to be displayed in the gallerysize
– Defines the size of the media in the gallery
Examples and Usage
Basic example – The shortcode can be used to display the entire gallery by using the shortcode [easymedia-gallery]. This will display the gallery with the default settings.
[easymedia-gallery]
Advanced examples
Displaying a specific media item from the gallery. In this example, we specify the media item by its ID, which is 5. This will display only the media item with the ID of 5.
[easymedia-gallery med=5]
Controlling the size of the media items in the gallery. In this example, we use the ‘size’ attribute to specify the size of the media items. The value ‘large’ will display the media items in a larger size.
[easymedia-gallery size=large]
Combining multiple attributes. In this example, we combine the ‘med’ and ‘size’ attributes. This will display the media item with the ID of 5 in a larger size.
[easymedia-gallery med=5 size=large]
PHP Function Code
In case you have difficulties debugging what causing issues with [easymedia-gallery]
shortcode, check below the related PHP functions code.
Shortcode line:
add_shortcode( 'easymedia-gallery', 'easy_media_gnl_shortcode' );
Shortcode PHP function:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 | function easy_media_gnl_shortcode( $attsn ) { if ( easy_get_option( 'easymedia_disen_plug' ) == '1' ) { extract( shortcode_atts( array ( 'med' => -1, 'size' => '' ), $attsn ) ); ob_start(); $paged = ( get_query_var( 'paged' ) ) ? get_query_var( 'paged' ) : 1; // for pagination $deff_img_limit = easy_get_option( 'easymedia_img_size_limit' ); // get the default image size limit $theopt = easy_get_option( 'easymedia_frm_size' ); $imwidth = stripslashes ( $theopt [ 'width' ] ); $imheight = stripslashes ( $theopt [ 'height' ] ); if ( $med > '0' ) { $finid = explode ( "," , $med ); $medinarr = $finid ; $emargs = emg_gallery_gen( $finid , $paged ); } $emg_query = new WP_Query( $emargs ); if ( $emg_query ->have_posts() ): $mediauniqueid = emgRandomString(6); //Random class for fitText echo '<div class="pagwrap"><div class="easycontainer emgclearfix">' ; echo '<div class="rig">' ; while ( $emg_query ->have_posts() ) : $emg_query ->the_post(); $images = get_post_meta( get_the_id(), 'easmedia_metabox_media_gallery' , true ); $isresize = get_post_meta( get_the_id(), 'easmedia_metabox_media_gallery_opt1' , true ); if ( is_array ( $images ) ) { $ig = 0; foreach ( $images as $img_id ) { $img = wp_get_attachment_image_src( $img_id , 'full' ); $img_url = easymedia_imgresize( $img [0], $deff_img_limit , $isresize , $img [1], $img [2] ); $img_url = explode ( "," , $img_url ); $img_info = get_post( $img_id ); $ext = pathinfo ( $img [0], PATHINFO_EXTENSION); $filenm = basename ( $img [0], "." . $ext ); $emgthumbimg = easymedia_resizer( $img [0], $img [1], $img [2], $imwidth , $imheight , true ); if ( get_post_meta( get_the_id(), 'easmedia_metabox_media_gallery_opt2' , true ) == 'on' ) { $thumbttl = $img_info ->post_title; $thumbttl = esc_html( esc_js( $thumbttl ) ); } else { $thumbttl = get_post_meta( get_the_id(), 'easmedia_metabox_title' , true ); } emg_gallery_markup( $imwidth , $imheight , get_the_id(). '-' . $img_id , $img_url [0], $emgthumbimg , $filenm , stripslashes ( $thumbttl ) ); } } else { echo '<div style="display:none"></div>' ; } ?> <?php endwhile ; else : echo '<div class="easymedia_center">' ; echo '<div class="view"><img src="' .plugins_url( 'images/ajax-loader.gif' , __FILE__ ). '" width="32" height="32"/></div>' ; $contnt = ob_get_clean(); return $contnt ; endif ; wp_reset_postdata(); echo '<div style="clear:both;"></div>' ; echo '</div></div>' ; // @since 1.3.75 if ( emg_get_aff_option( 'emg_affiliate_info' , 'emg_aff_id' , '' ) ) { echo '<span class="emg-aff-link">Powered by <a href="https://secure.ghozylab.com/demo/?ref=' .emg_get_aff_option( 'emg_affiliate_info' , 'emg_aff_id' , '' ). '&goto=emg" target="_blank">Easy Media Gallery Plugin</a></span>' ; } echo '</div>' ; // JS emg_put_script(); // Dinamic CSS echo '<style>/*Dynamic CSS - By GhozyLab*/' ; echo emg_dynamic_css_generator(); echo '</style>' ; $content = ob_get_clean(); return $content ; } else { ob_start(); echo '<div style="display: none;"></div>' ; $contnt = ob_get_clean(); return $contnt ; } } |
Code file location:
easy-media-gallery/easy-media-gallery/includes/shortcode.php
Conclusion
Now that you’ve learned how to embed the Gallery Plugin shortcodes, understood the parameters, and seen code examples, it’s easy to use and debug any issue that might cause it to ‘not work’. If you still have difficulties with it, don’t hesitate to leave a comment below.
Leave a Reply