Below, you’ll find a detailed guide on how to add the Photo Gallery Shortcode to your WordPress website, including its parameters, examples, and PHP function code. Additionally, we’ll assist you with common issues that might cause the Photo Gallery Plugin shortcode not to show or not to work correctly.
Before starting, here is an overview of the Photo Gallery Plugin and the shortcodes it provides:
"Photo Gallery by 10Web – Mobile-Friendly Image Gallery is a powerful WordPress plugin that lets you create responsive, beautifully designed galleries. It makes image presentation on mobiles a breeze."
- [Best_Wordpress_Gallery]
Photo Gallery [Best_Wordpress_Gallery] Shortcode
The Best_Wordpress_Gallery shortcode is utilized to display a variety of gallery types on your WordPress site. This shortcode fetches the gallery details from the database based on the ‘id’ parameter. It supports gallery types like thumbnails, slideshow, blog style, carousel, and album previews. The ‘gallery_type’ parameter defines the display style. If ‘ajax’ is set, it fetches the images asynchronously. The images are then looped through to generate the gallery, excluding embedded types.
Shortcode: [Best_Wordpress_Gallery]
Parameters
Here is a list of all possible Best_Wordpress_Gallery shortcode parameters and attributes:
id
– Unique identifier for the specific gallery.gallery_type
– Determines the gallery’s layout style.ajax
– Enables or disables Ajax for the gallery.
Examples and Usage
Basic example – Display a gallery using its ID
[Best_Wordpress_Gallery id=3 /]
Advanced examples
Display a gallery using its ID, and specify the gallery type as ‘thumbnails’.
[Best_Wordpress_Gallery id=3 gallery_type='thumbnails' /]
Display a gallery with a specific type and enable AJAX loading of images.
[Best_Wordpress_Gallery id=3 gallery_type='thumbnails' ajax=true /]
Display a gallery and specify the gallery type as ‘slideshow’.
[Best_Wordpress_Gallery id=3 gallery_type='slideshow' /]
Display a gallery with ‘album_compact_preview’ type.
[Best_Wordpress_Gallery id=3 gallery_type='album_compact_preview' /]
Display a gallery with ‘image_browser’ type.
[Best_Wordpress_Gallery id=3 gallery_type='image_browser' /]
These examples show how to utilize the ‘Best_Wordpress_Gallery’ shortcode to display galleries with different types and settings. By adjusting the parameters, you can customize the gallery to fit your specific needs.
PHP Function Code
In case you have difficulties debugging what causing issues with [Best_Wordpress_Gallery]
shortcode, check below the related PHP functions code.
Shortcode line:
add_shortcode('Best_Wordpress_Gallery', array($this, 'shortcode'));
Shortcode PHP function:
function shortcode( $params = array() ) {
if ( isset($params['id']) && $params['id'] ) {
global $wpdb;
$shortcode = $wpdb->get_var($wpdb->prepare("SELECT tagtext FROM " . $wpdb->prefix . "bwg_shortcode WHERE id='%d'", $params['id']));
if ($shortcode) {
$params = array_merge(WDWLibrary::parse_tagtext_to_array($shortcode), $params);
}
else {
return;
}
}
// 'gallery_type' is the only parameter not being checked.
// Checking for incomplete shortcodes.
$gallery_allowed_types = array(
'thumbnails',
'thumbnails_masonry',
'thumbnails_mosaic',
'slideshow',
'image_browser',
'blog_style',
'carousel',
'album_compact_preview',
'album_masonry_preview',
'album_extended_preview',
);
if ( isset($params['gallery_type']) && in_array($params['gallery_type'], $gallery_allowed_types) ) {
$pairs = WDWLibrary::get_shortcode_option_params( $params );
if ( isset($params['ajax']) ) {
$pairs['ajax'] = $params['ajax'];
}
$images = $this->get_shortcode_images( $pairs );
if ( is_array( $images ) ) {
foreach ( $images as $image ) {
if ( strpos($image->filetype, 'EMBED') === FALSE ) {
$this->images[] = array(
'src' => BWG()->upload_url . (isset($image->image_url_raw) ? $image->image_url_raw : $image->image_url),
'title' => $image->alt,
'alt' => $image->alt
);
}
}
}
}
}
Code file location:
photo-gallery/photo-gallery/framework/WDWSitemap.php
Conclusion
Now that you’ve learned how to embed the Photo Gallery Plugin shortcode, 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