Ok so I found the answer. I used the code as per https://wordpress.stackexchange.com/a/56426/37472 and changed all references of 'series'
to 'gallery'
.
That added the required rewritre rule to parse a link like domain.com/landscapes/gallery/123/
to index.php?attachment_id=123
.
My assumption was that wordpress would display the default permalink that is generated by get_permalink()
in the domain.com/landscapes/gallery/123/
format. It does not. However, I used a simple workaround in my gallery script to generate the anchor links in the required format, which is different for the home page, sub pages and parent/other pages. The script uses isotope and lazy load to load the galleries http://pastie.org/8294032.
For the different format of the pages, i modified the my_rewrite_rules_array( $rules )
function as follows:
function my_rewrite_rules_array( $rules ) {
$my_rules = array();
$my_rules['gallery/(\d+)/?$'] = 'index.php?attachment_id=$matches[1]';
$my_rules['(\w+)/gallery/(\d+)/?$'] = 'index.php?attachment_id=$matches[2]';
$my_rules['(\w+)/(\w+)/gallery/(\d+)/?$'] = 'index.php?attachment_id=$matches[3]';
return $my_rules + $rules;
}