DYNAMIC META DESCRIPTION TAGS MOD
This mod adds dynamic meta description tags to almost every page (categories, albums and images).
Meta description tag is filled respectively with category description, album description and image caption text, or, if it's not set, with a default site description set in config.inc.php.
HTML/BBCode tags stripped before building meta tag, if necessary.
Page number added both to meta description and page title in thumbnails page to avoid duplications when album spreads over multiple pages.
Thanks to GauGau for the hints above.
Files to edit:
include/config.inc.php
displayimage.php
index.php
thumbnails.php
lang/your_lang.php
OPEN
include/config.inc.php
FIND (at the end of file):
?>
BEFORE, ADD
// DEFAULT META DESCRIPTION TEXT
$CONFIG['meta_description'] = 'Your site default meta description text';
OPEN
displayimage.php
FIND (line 316)
if ($CURRENT_PIC_DATA['keywords']) { $meta_keywords = "<meta name=\"keywords\" content=\"".$CURRENT_PIC_DATA['keywords']."\"/>"; }
AFTER, ADD
$meta_description = empty($CURRENT_PIC_DATA['caption']) ? $CONFIG['meta_description'] : strip_tags(bb_decode($CURRENT_PIC_DATA['caption']));
$desc_len = strlen($meta_description);
if (!is_numeric($album)) $desc_len += strlen($album_name)+3;
if ($desc_len > 200) {
$offset = 170;
if (!is_numeric($album)) $offset -= strlen($album_name)+3;
$meta_description = substr($meta_description, 0, strpos($meta_description, " ", $offset))."...";
}
if (!is_numeric($album)) $meta_description .= " - " . $album_name;
$meta_description = "\n<meta name=\"description\" content=\"$meta_description\" />\n";
$meta_keywords .= $meta_description;
OPEN
index.php
FIND (line 756)
if (isset($cat)) {
BEFORE, ADD
$meta_description = $CONFIG['meta_description'];
FIND (line 757)
get_meta_album_set($cat,$META_ALBUM_SET);
AFTER, ADD
$result = cpg_db_query("SELECT description FROM {$CONFIG['TABLE_CATEGORIES']} WHERE cid = '$cat'");
if (mysql_num_rows($result) > 0) list($cat_desc) = mysql_fetch_array($result);
if (!empty($cat_desc)) {
$meta_description = strip_tags(bb_decode($cat_desc));
} else if ($cat >= FIRST_USER_CAT) {
$user_name = get_username($cat - FIRST_USER_CAT);
if (!$user_name) $user_name = 'Mr. X';
$meta_description = sprintf($lang_list_categories['xx_s_gallery'], $user_name);
}
mysql_free_result($result);
FIND (line 764)
pageheader($BREADCRUMB_TEXT ? $BREADCRUMB_TEXT : $lang_index_php['welcome']);
REPLACE WITH
$desc_len = strlen($meta_description);
if (isset($_GET['cat']) && $PAGE > 1) $desc_len += strlen($lang_index_php['page'] . " $PAGE")+3;
if ($desc_len > 200) {
$offset = 170;
if (isset($_GET['cat']) && $PAGE > 1) $offset -= strlen($lang_index_php['page'] . " $PAGE")+3;
$meta_description = substr($meta_description, 0, strpos($meta_description, " ", $offset))."...";
}
if (isset($_GET['cat']) && $PAGE > 1) $meta_description .= " - " . $lang_index_php['page'] . " $PAGE";
$meta_description = "<meta name=\"description\" content=\"$meta_description\" />\n";
$page_title = ($BREADCRUMB_TEXT) ? $BREADCRUMB_TEXT : $lang_index_php['welcome'];
if (isset($_GET['cat']) && $PAGE > 1) $page_title .= " - " . $lang_index_php['page'] . " $PAGE";
pageheader($page_title, $meta_description);
OPEN
thumbnails.php
FIND (line 163)
pageheader(isset($CURRENT_ALBUM_DATA) ? $CURRENT_ALBUM_DATA['title'] : $lang_meta_album_names[$album]);
REPLACE WITH
$page_title = (isset($CURRENT_ALBUM_DATA) ? $CURRENT_ALBUM_DATA['title'] : $lang_meta_album_names[$album]);
$meta_description = isset($CURRENT_ALBUM_DATA['description']) ? strip_tags(bb_decode($CURRENT_ALBUM_DATA['description'])) : $CONFIG['meta_description'];
$desc_len = strlen($meta_description);
if (isset($CURRENT_ALBUM_DATA)) $desc_len += strlen($lang_meta_album_names[$album])+3;
if ($page > 1) $desc_len += strlen($lang_thumbnails_php['page'] . " $page")+3;
if ($desc_len > 200) {
$offset = 170;
if (isset($CURRENT_ALBUM_DATA)) $offset -= strlen($lang_meta_album_names[$album])+3;
if ($page > 1) $offset -= strlen($lang_thumbnails_php['page'] . " $page")+3;
$meta_description = substr($meta_description, 0, strpos($meta_description, " ", $offset))."...";
}
if (!isset($CURRENT_ALBUM_DATA)) $meta_description .= " - " . $lang_meta_album_names[$album];
if ($page > 1) {
$page_title .= " - " . $lang_thumbnails_php['page'] . " $page";
$meta_description .= " - " . $lang_thumbnails_php['page'] . " $page";
}
$meta_description = "<meta name=\"description\" content=\"$meta_description\" />\n";
pageheader($page_title, $meta_description);
OPEN
lang/your_lang.php
FIND (line 1282)
);
$lang_album_admin_menu = array(
BEFORE, ADD (translate "Page" in your_lang!)
'page' => 'Page',
FIND (line 1714)
// ------------------------------------------------------------------------- //
// File thumbnails.php
// ------------------------------------------------------------------------- //
AFTER, ADD (translate "Page" in your_lang!)
if (defined('THUMBNAILS_PHP')) $lang_thumbnails_php = array(
'page' => 'Page'
);
FIND AND DELETE (line below)
// Void
SAVE AND CLOSE ALL FILES