WordPress NextGen Gallery – Page Title

clean page titles containing album/gallery names


You like the NextGen Gallery Plugin for WordPress, but you want ‘nicer’ name based page titles instead of something like “Album 78”, “Gallery 12” ?
Here is a simple solution, you just have to edit your theme files:

Page Title#

Mostly the title (<h1> Tag) ist set into your page.php file or alternative in your header.php file. To get nicer titles, based on the gallery/album names you can use the following code:

H1 Title#

// get ngg gallery info (note: the nggdb functions uses the wordpress buildin cache system, so don't worry about additional querys!)
$gallery = nggdb::find_gallery(get_query_var('gallery'));
$album = nggdb::find_album(get_query_var('album'));

// if the current page is a gallery, display the title
if ($gallery){
echo '<h1>', $gallery->title, '</h1>';

// otherwise, if it's an album, just show the name
}else if($album){
echo '<h1>', $album->name, '</h1>';
// on normal pages, show the title
echo '<h1>';
echo '</h1>';

Page Meta Title#

Currently only the h1-title is modified, to change the title in your browser window you can do it in the same way!

Title Tag#

// get ngg album info
$gallery = nggdb::find_gallery(get_query_var('gallery'));
$album = nggdb::find_album(get_query_var('album'));

<!-- Meta !-->

// nicer titles
if ($gallery){
echo $gallery->title.' | ';
}else if($album){
echo $album->name.' | ';
wp_title( '|', true, 'right' );

// Add the blog name.
bloginfo( 'name' );

// Add the blog description for the home/front page.
$site_description = get_bloginfo( 'description', 'display' );
if ( $site_description && ( is_home() || is_front_page())){
echo ' | ', $site_description;