NextGen Gallery tweaks

I have recently redesigned the website of my most historic client, the Scottish Volleyball Association, and the most challenging part has been to migrate the 550 galleries from the old symfony 1.x structure to the WordPress.

After trying quite a few solutions, I have settled for the most popular WordPress plugin, NextGen Gallery (Pro version) and never looked back.

The migration process has been quite straightforward (more on this in another post maybe later) and some technical issues have been quickly answered by the very efficient support team.

Some customization was however required due to the complex set up

For those using NextGen already, I have created my albums as main container per year (eg. 2019, 2018) and then attached my galleries into each album. This allowed me to have to build only 12 pages to display the galleries from 2007 to 2019 with the following simple shortcode in each page.

[ngg src=”albums” ids=”xx” display=”basic_extended_album” order_direction=”ASC” template=”basic-album”]

The first problem I have faced  was, because I didn’t have a post attached to each gallery there was no easy way for me to display the title the way I wanted in each gallery page.

Breadcumbs template to the rescue

I have however noticed that by enabling the breadcrumbs in the basic extended album setting the gallery title was retrieved by the plugin. I have thus decided to override this template and quickly came up with the following code to display the gallery title in the page.

$end = end($breadcrumbs);
<?php if(array_key_exists('name', $end)): ?>
<h2><?php echo $end['name']; ?></h2>
<?php endif; ?>

The second problem I noticed was the breadcrumb (included with Yoast SEO) which was not retrieving the gallery title either since there was no dedicated page created.

This time I have used a more complex filter to overcome my issue which is looking for a nggallery string in the request URI (default slug used by NextGen) and retrieve the matching album to append the correct breadcrumb to the existing array.

add_filter('wpseo_breadcrumb_links', 'yoast_seo_breadcrumb_append_link');
function yoast_seo_breadcrumb_append_link($links)
    $request_parts = explode('/', $_SERVER['REQUEST_URI']);
    if (in_array('nggallery', $request_parts)) {
        $gallery_slug = end($request_parts);
        global $wpdb;
        $gallery = $wpdb->get_results("SELECT * FROM {$wpdb->prefix}ngg_gallery WHERE `slug` = '$gallery_slug'", ARRAY_A);
        if ($gallery) {
            $links[] = array(
                'text' => $gallery[0]['title'],

    return $links;

I hope this would help someone with the same set up one day.

Do not hesitate to comment if you have any question.