• Welcome to Simple Machines Community Forum. Please login or sign up.
September 25, 2021, 02:13:39 AM

News:

SMF 2.1 RC4 has been released! Try it out and help us test! :) Read more.


Forum title modification

Started by juliereader, January 30, 2018, 06:04:48 AM

Previous topic - Next topic

juliereader

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

<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



Pipke

January 30, 2018, 04:09:06 PM #1 Last Edit: January 30, 2018, 04:28:46 PM by Pipke
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'

"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

juliereader

Quote from: Pipke on January 30, 2018, 04:09:06 PM


hi there,

thanks for the help.

here is my current code

<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.


Pipke

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

juliereader

Quote from: Pipke 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>';



here is the complete code




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 '


Pipke

make it like this


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

juliereader

Quote from: Pipke on January 31, 2018, 05:58:05 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  :)

Advertisement: