From 7b8b9a0bbabc1dfbf56cac8c105ad158ae78c3a7 Mon Sep 17 00:00:00 2001 From: Roman Kelesidis Date: Sat, 31 May 2025 10:13:55 +0300 Subject: [PATCH] feat: Added ability to set page meta description (#1917) * feat: Added ability to set page meta description * Update page_header.php * Update viewforum.php * Updated * Update viewtopic.php * Update viewtopic.php * Update viewtopic.php * Update viewtopic.php --- index.php | 3 +++ library/includes/page_header.php | 1 + styles/templates/default/page_header.tpl | 5 +++++ viewforum.php | 5 +++++ viewtopic.php | 5 +++++ 5 files changed, 19 insertions(+) diff --git a/index.php b/index.php index bc96573ee..2c752341c 100644 --- a/index.php +++ b/index.php @@ -45,6 +45,9 @@ if ($bb_cfg['show_network_news']) { // Init userdata $user->session_start(); +// Set meta description +$page_cfg['meta_description'] = $bb_cfg['site_desc']; + // Init main vars $viewcat = isset($_GET[POST_CAT_URL]) ? (int)$_GET[POST_CAT_URL] : 0; $lastvisit = IS_GUEST ? TIMENOW : $userdata['user_lastvisit']; diff --git a/library/includes/page_header.php b/library/includes/page_header.php index edd08f58b..f2f22581b 100644 --- a/library/includes/page_header.php +++ b/library/includes/page_header.php @@ -123,6 +123,7 @@ $template->assign_vars([ 'USE_TABLESORTER' => !empty($page_cfg['use_tablesorter']), 'ALLOW_ROBOTS' => !$bb_cfg['board_disable'] && (!isset($page_cfg['allow_robots']) || $page_cfg['allow_robots'] === true), + 'META_DESCRIPTION' => $page_cfg['meta_description'] ?? '', 'SITENAME' => $bb_cfg['sitename'], 'U_INDEX' => BB_ROOT . 'index.php', diff --git a/styles/templates/default/page_header.tpl b/styles/templates/default/page_header.tpl index 4fa536406..0ec5fb8f5 100644 --- a/styles/templates/default/page_header.tpl +++ b/styles/templates/default/page_header.tpl @@ -5,6 +5,11 @@ + + + + + <!-- IF HAVE_NEW_PM -->({HAVE_NEW_PM}) <!-- ENDIF --><!-- IF PAGE_TITLE -->{PAGE_TITLE} :: {SITENAME}<!-- ELSE -->{SITENAME}<!-- ENDIF --> diff --git a/viewforum.php b/viewforum.php index a8e17b581..d77d1ed99 100644 --- a/viewforum.php +++ b/viewforum.php @@ -51,6 +51,11 @@ if (!$forum_id or !$forum_data = @$forums['forum'][$forum_id]) { bb_die($lang['FORUM_NOT_EXIST']); } +// Set meta description +if (!empty($forum_data['forum_desc'])) { + $page_cfg['meta_description'] = $forum_data['forum_desc']; +} + // Make jumpbox make_jumpbox(); diff --git a/viewtopic.php b/viewtopic.php index 01e2de2e5..f952e0f15 100644 --- a/viewtopic.php +++ b/viewtopic.php @@ -671,6 +671,11 @@ for ($i = 0; $i < $total_posts; $i++) { $is_first_post = ($post_id == $t_data['topic_first_post_id']); + // Set meta description + if ($is_first_post || $i == 0) { + $page_cfg['meta_description'] = str_short(str_replace("\n", ' ', strip_tags(br2nl($message))), 220); + } + $template->assign_block_vars('postrow', [ 'ROW_CLASS' => !($i % 2) ? 'row1' : 'row2', 'POST_ID' => $post_id,