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:
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:
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