Advertisement:

Author Topic: Forum title modification  (Read 907 times)

Offline juliereader

  • Semi-Newbie
  • *
  • Posts: 39
Forum title modification
« on: January 30, 2018, 06:04:48 AM »
hi there,

I have a small issue.

Default SMF forum title tag has following pattern

Title: (Main Forum Name)
Title: (Category name)
Title: (Topic Title)


I changed it to
Title: (Main Forum Name)
Title: (Category name) - (Main Forum Name)
Title: (Topic Title) - (Main Forum Name)


using this

Code: [Select]
<title>',  $context['page_title_html_safe']. ' - ', strpos($context['page_title'],$context['forum_name']) === false ? $context['forum_name']. ' ' : '' , '</title>';
This code also checks if current page is forum homepage so it doesnt apply this template to home title to avoid repetition

Now the issue is my forum name is very large and i need it on homepage only, but that complete name is repeating in all titles which is annoying



So what i need is

Title: (Main Forum Name)
Title: (Category name) - (Custom Text)
Title: (Topic Title) - (Custom Text)


is it possible with some modification in above code ?



I am using SMB 2.0.15



Offline Pipke

  • Full Member
  • ***
  • Posts: 518
    • #31970508 on GitHub
Re: Forum title modification
« Reply #1 on: January 30, 2018, 04:09:06 PM »
try this edit in your index.template.php

Code: (find in not modified file) [Select]
echo '
<title>', $context['page_title_html_safe'], '</title>
i'm guessing in your modified file it will be then?
Code: (find) [Select]
echo '
<title>',  $context['page_title_html_safe']. ' - ', strpos($context['page_title'],$context['forum_name']) === false ? $context['forum_name']. ' ' : '' , '</title>';


Code: (replace by) [Select]
$custom_text = 'My Custom Text';
if ((empty($_REQUEST['action']) || $_REQUEST['action'] == 'collapse') && empty($_REQUEST['board']) && empty($_REQUEST['topic'])) // on homepage
echo '<title>',  $context['forum_name'] ,'</title>';
elseif (empty($_REQUEST['action']) || !empty($_REQUEST['board']) || !empty($_REQUEST['topic'])) // on board or topic
echo'<title>',  $context['forum_name'] ,' - ', $custom_text ,'</title>';
else // if not on homepage or board or topic
echo '<title>',   $context['page_title_html_safe'] ,'</title>';
echo'

« Last Edit: January 30, 2018, 04:28:46 PM by Pipke »
“If something is wrong, fix it if you can. But train yourself not to worry. Worry never fixes anything.”

My Mods for SMF:
Avatars Display Integration
Avatars on Board and/or MessageIndex
Recent Forum Topics on Boardindex
Relative Time Formats

Offline juliereader

  • Semi-Newbie
  • *
  • Posts: 39
Re: Forum title modification
« Reply #2 on: January 31, 2018, 04:59:20 AM »


hi there,

thanks for the help.

here is my current code

Code: [Select]
<title>',  $context['page_title_html_safe']. ' - ', strpos($context['page_title'],$context['forum_name']) === false ? $context['forum_name']. ' ' : '' , '</title>';
There is no echo ' in the beginning .


when i used your code, it gave me template parsing error.


Offline Pipke

  • Full Member
  • ***
  • Posts: 518
    • #31970508 on GitHub
Re: Forum title modification
« Reply #3 on: January 31, 2018, 05:32:37 AM »
can you please post your line above and the line below this
Code: (line) [Select]
<title>',  $context['page_title_html_safe']. ' - ', strpos($context['page_title'],$context['forum_name']) === false ? $context['forum_name']. ' ' : '' , '</title>';
“If something is wrong, fix it if you can. But train yourself not to worry. Worry never fixes anything.”

My Mods for SMF:
Avatars Display Integration
Avatars on Board and/or MessageIndex
Recent Forum Topics on Boardindex
Relative Time Formats

Offline juliereader

  • Semi-Newbie
  • *
  • Posts: 39
Re: Forum title modification
« Reply #4 on: January 31, 2018, 05:46:35 AM »
can you please post your line above and the line below this
Code: (line) [Select]
<title>',  $context['page_title_html_safe']. ' - ', strpos($context['page_title'],$context['forum_name']) === false ? $context['forum_name']. ' ' : '' , '</title>';


here is the complete code


Code: [Select]

echo ' 
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="description" content="', $context['page_title_html_safe'], '" />', !empty($context['meta_keywords']) ? '
<meta name="keywords" content="' . $context['meta_keywords'] . '" />' : '', '

<title>',  $context['page_title_html_safe']. ' - ', strpos($context['page_title'],$context['forum_name']) === false ? $context['forum_name']. ' ' : '' , '</title>';

echo '


Offline Pipke

  • Full Member
  • ***
  • Posts: 518
    • #31970508 on GitHub
Re: Forum title modification
« Reply #5 on: January 31, 2018, 05:58:05 AM »
make it like this
Code: [Select]

echo ' 
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="description" content="', $context['page_title_html_safe'], '" />', !empty($context['meta_keywords']) ? '
<meta name="keywords" content="' . $context['meta_keywords'] . '" />' : '';

$custom_text = 'My Custom Text';
if ((empty($_REQUEST['action']) || $_REQUEST['action'] == 'collapse') && empty($_REQUEST['board']) && empty($_REQUEST['topic'])) // on homepage
echo '<title>',  $context['forum_name'] ,'</title>';
elseif (empty($_REQUEST['action']) || !empty($_REQUEST['board']) || !empty($_REQUEST['topic'])) // on board or topic
echo'<title>',  $context['forum_name'] ,' - ', $custom_text ,'</title>';
else // if not on homepage or board or topic
echo '<title>',   $context['page_title_html_safe'] ,'</title>';

echo '
“If something is wrong, fix it if you can. But train yourself not to worry. Worry never fixes anything.”

My Mods for SMF:
Avatars Display Integration
Avatars on Board and/or MessageIndex
Recent Forum Topics on Boardindex
Relative Time Formats

Offline juliereader

  • Semi-Newbie
  • *
  • Posts: 39
Re: Forum title modification
« Reply #6 on: January 31, 2018, 06:59:52 AM »


thank you very much.

I make it work by simply replacing

$context['forum_name']  with this $context['page_title_html_safe']

on 8th line

THANK YOU VERY MUCH AGAIN  :)