NextGEN Gallery Shortcodes

Below, you’ll find a detailed guide on how to add the WordPress Gallery – NextGEN 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 WordPress Gallery – NextGEN Gallery Plugin shortcodes not to show or not to work correctly.

Before starting, here is an overview of the WordPress Gallery – NextGEN Gallery Plugin and the shortcodes it provides:

Plugin Icon
WordPress Gallery Plugin – NextGEN Gallery

"WordPress Gallery Plugin – NextGEN Gallery is a powerful tool for managing and displaying image galleries in WordPress. It offers a wide range of customizable features, making it ideal for photographers, artists, and web designers."

★★★★✩ (4151) Active Installs: 500000+ Tested with: 6.3.2 PHP Version: 5.6
Included Shortcodes:
  • [nggalbum]
  • [nggrandom]
  • [nggrecent]
  • [nggthumb]
  • [nggslideshow]
  • [nggallery]
  • [nggtags]
  • [nggimagebrowser]
  • [nggsingleepic]
  • [nggtagcloud]
  • [ngg_images]
  • [singlepic]
  • [ngg]

NextGEN Gallery [nggalbum] Shortcode

The nextgen-gallery shortcode is a powerful tool that allows you to display your image albums. It fetches the source, identifiers of the containers, and the display type. This shortcode works by taking in parameters, extracting the source, container IDs, and display type. Then, it removes the ID parameter and returns the rest.

Shortcode: [nggalbum]

Parameters

Here is a list of all possible nggalbum shortcode parameters and attributes:

  • source – Determines the source of the gallery, default is ‘albums’.
  • id – Unique identifier for the album to display.
  • display_type – Defines the album’s display style, default is compact.

Examples and Usage

Basic example – The basic usage of the nggalbum shortcode is to display a specific album by referencing its ID.

[nggalbum id=1 /]

Advanced examples

Using the shortcode to display an album by referencing its ID and setting the source to ‘galleries’. This will display all the galleries within the specified album.

[nggalbum id=1 source="galleries" /]

Another advanced usage is to display an album by referencing its ID and specifying the display type. In this case, the display type is set to NGG_BASIC_EXTENDED_ALBUM, which will display the album in an extended format.

[nggalbum id=1 display_type=NGG_BASIC_EXTENDED_ALBUM /]

PHP Function Code

In case you have difficulties debugging what causing issues with [nggalbum] shortcode, check below the related PHP functions code.

Shortcode PHP function:

function ngglegacy_shortcode($params)
    {
        $params['source']           = $this->_get_param('source', 'albums', $params);
        $params['container_ids']    = $this->_get_param('id', NULL, $params);
        $params['display_type']     = $this->_get_param('display_type', NGG_BASIC_COMPACT_ALBUM, $params);

        unset($params['id']);
        return $params;
    }

NextGEN Gallery [nggrandom] Shortcode

The NextGEN Gallery shortcode is used to display random images from your gallery. This PHP function renders random images based on specified parameters. It sets the source to ‘random’, determines the number of images per page, and enables or disables pagination. If an ‘id’ is provided, it’s used as the container id for image display. Unnecessary parameters ‘max’ and ‘id’ are unset at the end.

Shortcode: [nggrandom]

Parameters

Here is a list of all possible nggrandom shortcode parameters and attributes:

  • source – determines the source of the images, defaulting to ‘random’.
  • images_per_page – sets the maximum number of images displayed, no default value.
  • disable_pagination – disables pagination when set to TRUE, default is TRUE.
  • display_type – sets the type of display for the images, default is NGG_BASIC_THUMBNAILS.
  • id – specifies the unique identifier of the gallery.
  • container_ids – sets the container ID for the images, only when ‘id’ is set.

Examples and Usage

Basic example – A simple usage of the ‘nggrandom’ shortcode to display random images from your NextGEN Gallery.

[nggrandom /]

Advanced examples

Displaying random images but limiting the number of images per page to 5. If there are more than 5 images, pagination will be enabled.

[nggrandom max=5 /]

Displaying random images from a specific gallery (for example, gallery with ID 3), and disabling pagination regardless of the number of images in the gallery.

[nggrandom id=3 disable_pagination=1 /]

Displaying random images, limiting the number of images per page to 10, and changing the display type to ‘NGG_BASIC_SLIDESHOW’ which will display the images in a slideshow format.

[nggrandom max=10 display_type='NGG_BASIC_SLIDESHOW' /]

PHP Function Code

In case you have difficulties debugging what causing issues with [nggrandom] shortcode, check below the related PHP functions code.

Shortcode PHP function:

function render_random_images($params)
	{
		$params['source']             = $this->_get_param('source', 'random', $params);
        $params['images_per_page']    = $this->_get_param('max', NULL, $params);
        $params['disable_pagination'] = $this->_get_param('disable_pagination', TRUE, $params);
        $params['display_type']       = $this->_get_param('display_type', NGG_BASIC_THUMBNAILS, $params);

        // inside if because Mixin_Displayed_Gallery_Instance_Methods->get_entities() doesn't handle NULL container_ids correctly
        if (isset($params['id']))
            $params['container_ids'] = $this->_get_param('id', NULL, $params);

        unset($params['max']);
        unset($params['id']);
        return $params;
	}

NextGEN Gallery [nggrecent] Shortcode

The NextGEN Gallery shortcode is designed to render recent images. It allows customization of source, the maximum number of images displayed, pagination, and display type.

Shortcode: [nggrecent]

Parameters

Here is a list of all possible nggrecent shortcode parameters and attributes:

  • source – Defines the source of images, default is ‘recent’.
  • images_per_page – Sets the maximum number of images per page.
  • disable_pagination – If true, disables pagination, default is true.
  • display_type – Sets the display type, default is NGG_BASIC_THUMBNAILS.
  • id – Specifies the unique identifier of the gallery.
  • container_ids – If ‘id’ is set, it specifies container’s unique identifier.

Examples and Usage

Basic example – A simple usage of the nggrecent shortcode to display recent images.

[nggrecent /]

Advanced examples

Display recent images with a maximum limit. This shortcode will display the most recent images up to the given maximum number.

[nggrecent max=10 /]

Display recent images from a specific source. This shortcode will display the most recent images from the given source id.

[nggrecent source="gallery" id=2 /]

Display recent images with a specific display type. This shortcode will display the most recent images with the given display type.

[nggrecent display_type="slideshow" /]

Display recent images with pagination disabled. This shortcode will display the most recent images in one single page without pagination.

[nggrecent disable_pagination=true /]

PHP Function Code

In case you have difficulties debugging what causing issues with [nggrecent] shortcode, check below the related PHP functions code.

Shortcode PHP function:

function render_recent_images($params)
	{
        $params['source']             = $this->_get_param('source', 'recent', $params);
        $params['images_per_page']    = $this->_get_param('max', NULL, $params);
        $params['disable_pagination'] = $this->_get_param('disable_pagination', TRUE, $params);
        $params['display_type']       = $this->_get_param('display_type', NGG_BASIC_THUMBNAILS, $params);

        if (isset($params['id']))
            $params['container_ids'] = $this->_get_param('id', NULL, $params);

        unset($params['max']);
        unset($params['id']);
        return $params;
	}

NextGEN Gallery [nggthumb] Shortcode

The NextGEN Gallery shortcode is a tool that generates thumbnail images from specified galleries. The PHP code associated with this shortcode retrieves the ‘id’, ‘source’, and ‘display_type’ parameters. It then removes the ‘id’ and returns the modified parameters. This allows users to easily customize the display of thumbnails in their WordPress galleries.

Shortcode: [nggthumb]

Parameters

Here is a list of all possible nggthumb shortcode parameters and attributes:

  • id – Identifies the specific gallery or image.
  • source – Defines where the images are coming from, default is ‘galleries’.
  • display_type – Determines how the images will be displayed, default is ‘NGG_BASIC_THUMBNAILS’.

Examples and Usage

Basic example – A simple usage of the nggthumb shortcode to display the thumbnails from a gallery with the id of 1.

[nggthumb id=1 /]

Advanced examples

Displaying the thumbnails from a gallery with the id of 2, but specifying the source as ‘albums’ instead of the default ‘galleries’.

[nggthumb id=2 source=albums /]

Displaying the thumbnails from a gallery with the id of 3, specifying the source as ‘tags’ and overriding the default display type to show as NGG_BASIC_IMAGEBROWSER.

[nggthumb id=3 source=tags display_type=NGG_BASIC_IMAGEBROWSER /]

PHP Function Code

In case you have difficulties debugging what causing issues with [nggthumb] shortcode, check below the related PHP functions code.

Shortcode PHP function:

function render_thumb_shortcode($params)
	{
		$params['entity_ids']   = $this->_get_param('id', NULL, $params);
        $params['source']       = $this->_get_param('source', 'galleries', $params);
        $params['display_type'] = $this->_get_param('display_type', NGG_BASIC_THUMBNAILS, $params);
        unset($params['id']);
        return $params;
	}

NextGEN Gallery [nggslideshow] Shortcode

The NextGEN Gallery shortcode is a powerful tool that renders a slideshow on your webpage. This shortcode utilizes parameters like ‘gallery_ids’, ‘display_type’, ‘gallery_width’, and ‘gallery_height’ to customize the slideshow. It fetches the gallery IDs, sets the display type to a basic slideshow, and adjusts the width and height as per user specifications.

Shortcode: [nggslideshow]

Parameters

Here is a list of all possible nggslideshow shortcode parameters and attributes:

  • id – Unique identifier for the specific gallery
  • display_type – Defines the type of gallery display
  • w – Sets the width of the gallery
  • h – Sets the height of the gallery

Examples and Usage

Basic example – A simple slideshow display using the nggslideshow shortcode.

[nggslideshow id=10 /]

Advanced examples

Display a slideshow with specified width and height. If the width and height are not found, the slideshow will display with default dimensions.

[nggslideshow id=10 w=500 h=300 /]

Display a slideshow with a specific display type. If the display type is not found, the slideshow will display with the basic slideshow type.

[nggslideshow id=10 display_type="fancy" /]

Combine multiple parameters to create a more complex slideshow. This example includes the gallery id, width, height, and display type.

[nggslideshow id=10 w=500 h=300 display_type="fancy" /]

PHP Function Code

In case you have difficulties debugging what causing issues with [nggslideshow] shortcode, check below the related PHP functions code.

Shortcode PHP function:

function render_slideshow($params)
	{
		$params['gallery_ids']    = $this->_get_param('id', NULL, $params);
        $params['display_type']   = $this->_get_param('display_type', NGG_BASIC_SLIDESHOW, $params);
        $params['gallery_width']  = $this->_get_param('w', NULL, $params);
        $params['gallery_height'] = $this->_get_param('h', NULL, $params);
        unset($params['id'], $params['w'], $params['h']);
        return $params;
	}

NextGEN Gallery [nggallery] Shortcode

The NextGEN Gallery shortcode is used to display a gallery within a post or page. The PHP code for this shortcode fetches the ‘id’ and ‘display_type’ parameters, which specify the gallery to display and its format. If an ‘images’ parameter is set, it determines the number of images to show per page.

Shortcode: [nggallery]

Parameters

Here is a list of all possible nggallery shortcode parameters and attributes:

  • id – Specifies the unique identifier for the gallery.
  • display_type – Determines the gallery’s display style.
  • images – Sets the number of images per page.

Examples and Usage

Basic example – The following shortcode represents the simplest way to use the nggallery shortcode by specifying the gallery id parameter.

[nggallery id=1 /]

Advanced examples

1. Displaying a specific number of images from a gallery – This shortcode allows you to specify the amount of images to be displayed from a specific gallery. The parameter ‘images’ determines the number of images displayed.

[nggallery id=1 images=10 /]

2. Specifying the display type – With this shortcode, you can specify the display type for a gallery. The parameter ‘display_type’ can be set to various values such as NGG_BASIC_THUMBNAILS, NGG_BASIC_SLIDESHOW, etc.

[nggallery id=1 display_type=NGG_BASIC_THUMBNAILS /]

3. Combining multiple parameters – This shortcode combines the use of multiple parameters. It specifies the gallery id, the number of images to be displayed, and the display type.

[nggallery id=1 images=10 display_type=NGG_BASIC_SLIDESHOW /]

PHP Function Code

In case you have difficulties debugging what causing issues with [nggallery] shortcode, check below the related PHP functions code.

Shortcode PHP function:

function render_nggallery($params)
    {
        $params['gallery_ids']     = $this->_get_param('id', NULL, $params);
        $params['display_type']    = $this->_get_param('display_type', NGG_BASIC_THUMBNAILS, $params);
        if (isset($params['images']))
            $params['images_per_page'] = $this->_get_param('images', NULL, $params);
        unset($params['id']);
        unset($params['images']);
        return $params;
    }

NextGEN Gallery [nggtags] Shortcode

The nextgen-gallery shortcode is a tool that renders images based on specific tags. The PHP code for this shortcode fetches the ‘gallery’ or ‘album’ parameters from the tags, determines the source, and sets the display type. It removes the ‘gallery’ parameter and returns the rest.

Shortcode: [nggtags]

Parameters

Here is a list of all possible nggtags shortcode parameters and attributes:

  • tag_ids – Specifies the tags related to the gallery or album
  • source – Defines the source of the images, default is ‘tags’
  • display_type – Determines how images are displayed, default is basic thumbnails
  • gallery – Gallery identifier, removed after use

Examples and Usage

Basic example – A simple use of the nggtags shortcode to render a gallery based on tags. In this case, we’re using the tag ‘nature’ as the parameter.

[nggtags gallery="nature" /]

Advanced examples

Using the nggtags shortcode to render a gallery based on multiple tags. Here, we’re using the tags ‘nature’ and ‘city’ as the parameters. The gallery will display thumbnails from both ‘nature’ and ‘city’ tagged images.

[nggtags gallery="nature,city" /]

Using the nggtags shortcode with a different display type. By default, the display type is set to NGG_BASIC_THUMBNAILS. However, you can change this to other display types such as NGG_BASIC_IMAGEBROWSER or NGG_BASIC_SLIDESHOW. In this example, we’re using the ‘city’ tag and setting the display type to NGG_BASIC_SLIDESHOW.

[nggtags gallery="city" display_type="NGG_BASIC_SLIDESHOW" /]

Using the nggtags shortcode with a custom source. By default, the source is set to ‘tags’. However, you can change this to a custom source. In this example, we’re using the ‘nature’ tag and setting the source to ‘custom_source’.

[nggtags gallery="nature" source="custom_source" /]

PHP Function Code

In case you have difficulties debugging what causing issues with [nggtags] shortcode, check below the related PHP functions code.

Shortcode PHP function:

function render_based_on_tags($params)
    {
        $params['tag_ids']      = $this->_get_param('gallery', $this->_get_param('album', array(), $params), $params);
        $params['source']       = $this->_get_param('source', 'tags', $params);
        $params['display_type'] = $this->_get_param('display_type', NGG_BASIC_THUMBNAILS, $params);
        unset($params['gallery']);
        return $params;
    }

NextGEN Gallery [nggimagebrowser] Shortcode

The NextGEN Gallery shortcode is a powerful tool for displaying images on your website. The shortcode fetches gallery IDs, source, and display type parameters. It then removes the ‘id’ parameter and returns the remaining parameters. This allows you to customize the image display.

Shortcode: [nggimagebrowser]

Parameters

Here is a list of all possible nggimagebrowser shortcode parameters and attributes:

  • id – The unique identifier of the gallery.
  • source – Defines the source of the images, default value is ‘galleries’.
  • display_type – Determines how images will be displayed, default is NGG_BASIC_IMAGEBROWSER.

Examples and Usage

Basic example – A fundamental usage of the nggimagebrowser shortcode can be seen in the following example. Here, the shortcode is used to display an image gallery by referencing the gallery ID. The gallery ID should be replaced with the actual ID of the gallery you want to display.

[nggimagebrowser id=1 /]

Advanced examples

The nggimagebrowser shortcode can also be used with multiple parameters to customize the display. In the following example, the shortcode is used to display an image gallery by referencing the gallery ID, source, and display type. The gallery ID should be replaced with the actual ID of the gallery you want to display. The source parameter can be set to ‘galleries’ or ‘albums’. The display type parameter can be set to NGG_BASIC_IMAGEBROWSER for a basic image browser display.

[nggimagebrowser id=1 source='galleries' display_type=NGG_BASIC_IMAGEBROWSER /]

Another advanced usage of the nggimagebrowser shortcode can be seen in the next example. Here, the shortcode is used to display an image gallery by referencing only the source and display type, without specifying the gallery ID. This can be useful when you want to display all galleries or albums in a basic image browser display.

[nggimagebrowser source='galleries' display_type=NGG_BASIC_IMAGEBROWSER /]

PHP Function Code

In case you have difficulties debugging what causing issues with [nggimagebrowser] shortcode, check below the related PHP functions code.

Shortcode PHP function:

function render_shortcode($params)
    {
        $params['gallery_ids']  = $this->_get_param('id', NULL, $params);
        $params['source']       = $this->_get_param('source', 'galleries', $params);
        $params['display_type'] = $this->_get_param('display_type', NGG_BASIC_IMAGEBROWSER, $params);

        unset($params['id']);
        return $params;
    }

NextGEN Gallery [nggsingleepic] Shortcode

The NextGEN Gallery shortcode is a tool to display a single image on your website. The PHP function ‘render_singlepic’ takes parameters for ‘display_type’ and ‘image_ids’. It sets the display type to ‘NGG_BASIC_SINGLEPIC’ and fetches the image using its ID. The ‘id’ parameter is then removed. This function returns the parameters, rendering a single image on the webpage.

Shortcode: [nggsingleepic]

Parameters

Here is a list of all possible nggsingleepic shortcode parameters and attributes:

  • display_type – Defines the type of gallery display, default is NGG_BASIC_SINGLEPIC
  • image_ids – Represents the unique identifier of the image, obtained from ‘id’
  • id – Serves as the unique identifier of the image, removed after usage

Examples and Usage

Basic example – Display a single image using its ID

[nggsinglepic id=3 /]

This shortcode will render a single image from the NextGen gallery plugin. The ‘id’ parameter refers to the ID of the image you want to display. In this case, the image with ID 3 will be shown.

Advanced examples

Display a single image with a specific display type

[nggsinglepic id=3 display_type=2 /]

In this example, the ‘display_type’ parameter is used to specify the way the image is displayed. The value 2 might refer to a specific display style in the NextGen gallery plugin.

Display multiple images

[nggsinglepic image_ids=3,4,5 /]

This shortcode will display multiple images from the NextGen gallery plugin. The ‘image_ids’ parameter is a comma-separated list of image IDs. In this case, the images with IDs 3, 4, and 5 will be displayed.

PHP Function Code

In case you have difficulties debugging what causing issues with [nggsingleepic] shortcode, check below the related PHP functions code.

Shortcode PHP function:

function render_singlepic($params)
	{
		$params['display_type'] = $this->_get_param('display_type', NGG_BASIC_SINGLEPIC, $params);
        $params['image_ids'] = $this->_get_param('id', NULL, $params);
        unset($params['id']);
        return $params;
	}

NextGEN Gallery [nggtagcloud] Shortcode

The NextGEN Gallery shortcode is designed to render a specific tag cloud based on the parameters set. This function fetches the ‘tagcloud’, ‘source’, and ‘display_type’ parameters, defaulting to ‘yes’, ‘tags’, and ‘NGG_BASIC_TAGCLOUD’ respectively. It returns these parameters for use in the gallery.

Shortcode: [nggtagcloud]

Parameters

Here is a list of all possible nggtagcloud shortcode parameters and attributes:

  • tagcloud – Determines if the tag cloud is shown, default is ‘yes’
  • source – Defines the source of tags, default is ‘tags’
  • display_type – Sets the display type of the tag cloud, default is NGG_BASIC_TAGCLOUD

Examples and Usage

Basic example – A simple usage of the nggtagcloud shortcode without any additional parameters. This will display a basic tag cloud.

[nggtagcloud /]

Advanced examples

Example 1 – In this example, the nggtagcloud shortcode is used with the ‘tagcloud’ parameter set to ‘no’. This means the tag cloud will not be displayed.

[nggtagcloud tagcloud="no" /]

Example 2 – This example shows the nggtagcloud shortcode with the ‘source’ parameter set to ‘albums’. This will display a tag cloud based on album tags instead of image tags.

[nggtagcloud source="albums" /]

Example 3 – This advanced example includes the ‘display_type’ parameter set to NGG_BASIC_THUMBNAILS. This will display a tag cloud with thumbnail images.

[nggtagcloud display_type="NGG_BASIC_THUMBNAILS" /]

Example 4 – In this final example, multiple parameters are used. The ‘tagcloud’ parameter is set to ‘no’, the ‘source’ parameter is set to ‘albums’, and the ‘display_type’ is set to NGG_BASIC_THUMBNAILS. This will not display the tag cloud, but will show album tags with thumbnail images.

[nggtagcloud tagcloud="no" source="albums" display_type="NGG_BASIC_THUMBNAILS" /]

PHP Function Code

In case you have difficulties debugging what causing issues with [nggtagcloud] shortcode, check below the related PHP functions code.

Shortcode PHP function:

function render_shortcode($params)
    {
	    $params['tagcloud']     = $this->_get_param('tagcloud', 'yes', $params);
        $params['source']       = $this->_get_param('source', 'tags', $params);
        $params['display_type'] = $this->_get_param('display_type', NGG_BASIC_TAGCLOUD, $params);
        return $params;
    }

NextGEN Gallery [ngg_images] Shortcode

The NextGEN Gallery shortcode is a powerful tool that displays images in a gallery format. Using the ‘display_images’ function, this shortcode calls the ‘C_Displayed_Gallery_Renderer’ instance to render and display images according to the parameters passed. It allows customization of the displayed gallery, enhancing the visual appeal of your site.

Shortcode: [ngg_images]

Examples and Usage

Basic Example – A simple usage of the ngg_images shortcode to display a gallery. The ‘gallery_ids’ parameter specifies the ID of the gallery to be displayed.

[ngg_images gallery_ids=1]

Advanced Examples

Using the shortcode to display images from multiple galleries. The ‘gallery_ids’ parameter accepts a comma-separated list of gallery IDs.

[ngg_images gallery_ids="1,2,3"]

Using the shortcode to display images with a specific template. The ‘template’ parameter specifies the name of the template to be used for displaying the images.

[ngg_images gallery_ids=1 template="sample"]

Using the shortcode to display images with a specific order. The ‘order_by’ parameter specifies the field to order the images by, and the ‘order_direction’ parameter specifies the direction of the order.

[ngg_images gallery_ids=1 order_by="imagedate" order_direction="DESC"]

Using the shortcode to display a specific number of images. The ‘images_per_page’ parameter specifies the number of images to display per page.

[ngg_images gallery_ids=1 images_per_page=10]

PHP Function Code

In case you have difficulties debugging what causing issues with [ngg_images] shortcode, check below the related PHP functions code.

Shortcode PHP function:

function display_images($params, $inner_content=NULL)
	{
		$renderer = C_Displayed_Gallery_Renderer::get_instance();
		return $renderer->display_images($params, $inner_content);
	}

NextGEN Gallery [singlepic] Shortcode

The NextGEN Gallery shortcode is used to add images to your WordPress site. This shortcode accepts an ‘id’ attribute, which represents the image IDs. It fetches these images from the database and stores their details in an array. If the image has a title or alt text, these are also stored. The final array of image data can then be used elsewhere in your code.

Shortcode: [singlepic]

Parameters

Here is a list of all possible singlepic shortcode parameters and attributes:

  • id – The specific identifier for the image(s) to be displayed

Examples and Usage

Basic example – A simple usage of the ‘singlepic’ shortcode to display a single image by referencing its ID.

[singlepic id=1 /]

Advanced examples

Display two images by referencing their IDs. This will display the two images in the order of the IDs provided.

[singlepic id=1,2 /]

Display three images by referencing their IDs. This will display the three images in the order of the IDs provided. This is an example of how you can use multiple parameters with the ‘singlepic’ shortcode.

[singlepic id=1,2,3 /]

Please note that the IDs used in these examples are just placeholders. Replace them with the actual IDs of the images you want to display.

PHP Function Code

In case you have difficulties debugging what causing issues with [singlepic] shortcode, check below the related PHP functions code.

Shortcode PHP function:

function add_images( $atts ) {

        $tmp = shortcode_atts(array('id' => 0), $atts, 'ngg');
        extract($tmp);

        // make an array out of the ids (for thumbs shortcode))
        $pids = explode( ',', $id );

        // Some error checks
        if ( count($pids) == 0 )
            return '';

        $images = nggdb::find_images_in_list( $pids );

        foreach ($images as $image) {
            $newimage = array();
            $newimage['src']   = $newimage['sc'] = $image->imageURL;
            if ( !empty($image->title) )
                $newimage['title'] = $image->title;
            if ( !empty($image->alttext) )
                $newimage['alt']   = $image->alttext;
            $this->images[] = $newimage;
        }

        return '';
    }

NextGEN Gallery [ngg] Shortcode

The NextGEN Gallery shortcode is a powerful tool that generates a dynamic gallery display from selected images. The function ‘wpseo_shortcode_handler’ takes parameters and inner content. It uses the ‘C_Displayed_Gallery_Renderer’ instance to convert parameters into a gallery display. If the gallery is successfully created, it iterates through each image, adjusting the image size based on settings, and storing image details such as source, alt text, and title for SEO purposes.

Shortcode: [ngg]

Examples and Usage

Basic example – Showcases a simple usage of the ‘ngg’ shortcode to display a gallery by its ID.

[ngg id=1 /]

Advanced examples

Using the shortcode to display a gallery by referencing both ID and template. The gallery will first try to load by ID, and then apply the specified template.

[ngg id=1 template=carousel /]

Using the shortcode to display a gallery by referencing both ID and display type. The gallery will first try to load by ID, and then apply the specified display type.

[ngg id=1 display_type=photocrati-nextgen_basic_thumbnails /]

Using the shortcode to display a gallery by referencing the ID, template, and display type. The gallery will first try to load by ID, apply the specified template, and then the specified display type.

[ngg id=1 template=carousel display_type=photocrati-nextgen_basic_thumbnails /]

PHP Function Code

In case you have difficulties debugging what causing issues with [ngg] shortcode, check below the related PHP functions code.

Shortcode PHP function:

function wpseo_shortcode_handler($params, $inner_content = NULL)
    {
        $renderer = C_Displayed_Gallery_Renderer::get_instance();
        $displayed_gallery = $renderer->params_to_displayed_gallery($params);

        if ($displayed_gallery)
        {
            $gallery_storage = C_Gallery_Storage::get_instance();
            $settings		 = C_NextGen_Settings::get_instance();
            $source          = $displayed_gallery->get_source();
            if (in_array('image', $source->returns))
            {
                foreach ($displayed_gallery->get_entities() as $image) {
                    $named_image_size = $settings->imgAutoResize ? 'full' : 'thumb';
                    $sitemap_image = array(
                        'src'	=>	$gallery_storage->get_image_url($image, $named_image_size),
                        'alt'	=>	$image->alttext,
                        'title'	=>	$image->description ? $image->description: $image->alttext
                    );
                    $this->wpseo_images[] = $sitemap_image;
                }
            }
        }
    }

Conclusion

Now that you’ve learned how to embed the WordPress Gallery – NextGEN 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.

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *