Adding keyword and description meta tags to Gallery2

The File

Find the theme.tpl file for your current theme. I found mine here:
gallery2/themes/matrix/templates/theme.tpl

Copy this file to your desktop and open it with your favorite text editor (notepad, perhaps). I prefer Notepad++.

The Code

Add the following lines below the <head> tag near the top of the document:


<meta name="keywords" content="{$theme.item.keywords|markup:strip|default:$theme.item.pathComponent}" />
<meta name="description" content="{$theme.item.description|markup:strip|default:$theme.item.pathComponent}" />

Put it Back

Inside the templates directory, create a new folder called local and upload your modified template.tpl into there. The final path should be something like:
gallery2/themes/matrix/templates/local/theme.tpl

Gallery2 looks in the local directory first so that it loads your customized files if there are any. This protects your modified files from being overwritten after a Gallery2 update.

All Done

After this, you’re all done. Load up a gallery page and view source to see the keyword and description tags implemented. If you don’t have any keywords or a description for the album/item, then the path component will be used.

Update: 4/20/09

Thanks to a pingback from Mike Totzke’s blog, I realized that I had the wrong file path posted.  It’s updated now.  Thanks Mike!

One thought on “Adding keyword and description meta tags to Gallery2”

Leave a Reply