[Plugin: NextGEN Gallery] Clean/SEO URL solution
-
Here’s a very quick hack to demo how easy it would be to have clean, SEO friendly URL structure for *all* albums and galleries without having to resort to:
/nggallery/page-202/album-2/gallery-3/
1. Gallery > Options > General Options > Activate permalinks [ empty ] do not tick this box
2. Create a new Page to act as gallery main slug (this must match 1st segment in rewrite rule, see below):
/gallery
3. Insert the ngg shortcode (so nextgen code is run)
[album id=1 template=compact]
4. Visit URL:
https://mysite.com/gallery/album-name/gallery-name/
File: nggfunctions.php
Line #330 in function nggShowAlbum()
// $_GET from wp_query $gallery = get_query_var('gallery'); $album = get_query_var('album'); global $wpdb; $album_result = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $wpdb->nggalbum WHERE name = '%s'", $album) ); $gallery_result = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $wpdb->nggallery WHERE name = '%s'", $gallery ) ); $album = $album_result->id; $gallery = $gallery_result->gid;
File: THEME/functions.php
add_filter('rewrite_rules_array','wp_insertMyRewriteRules'); add_filter('query_vars','wp_insertMyRewriteQueryVars'); add_filter('init','flushRules'); // Remember to flush_rules() when adding rules function flushRules() { global $wp_rewrite; $wp_rewrite->flush_rules(); } // Adding a new rule function wp_insertMyRewriteRules($rules) { $newrules = array(); $newrules['(gallery)/([a-z\-]*)/([a-z\-]*)$'] = 'index.php?pagename=$matches[1]&album=$matches[2]&gallery=$matches[3]'; return $newrules + $rules; } // Adding the id var so that WP recognizes it function wp_insertMyRewriteQueryVars($vars) { array_push($vars, 'id'); return $vars; }
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
- The topic ‘[Plugin: NextGEN Gallery] Clean/SEO URL solution’ is closed to new replies.