Edit Page Title For Each Category / Board

Started by brettuk, April 02, 2018, 02:30:15 PM

Previous topic - Next topic

brettuk

Hi,

I am loving the SEO support that SMF brings, it's brilliant.

I have a question ...

Is there any MOD or anything out there that allows me to assign a unique title tag to each category/board?

At the moment, let's assume I have a board called 'General Discussion', it's H1 tag will be 'General Discussion and the page title will be the following:

<title>General Discussion</title>

Is there any way I am able to edit this, without having to put extra keywords into the board name, as that'll look bad for UX (user experience)?

Thanks!


Thanks!

Kindred

no...


Although you could try the Optimus Brave mod.

However, stuffing keywords into the title will actually have a NEGATIVE impact on SEO.
Слaва
Украинi

Please do not PM, IM or Email me with support questions.  You will get better and faster responses in the support boards.  Thank you.

"Loki is not evil, although he is certainly not a force for good. Loki is... complicated."

brettuk

Shame, it shouldn't do, if used correctly.

E.G if you're looking to get ranked for, 'Gaming Forum'

A title like 'Gaming Forum - The Number #1 Gaming Forum In The UK' would be better than just 'Gaming Forum'.

But you couldn't call the board that, as it'll look silly.

:)

drewactual

this little script will do this- it's a handy little booger and clean as a whistle (for a booger)... i'm swiping it from another post i made to keep from typing it again.  I use it for altering header image of boards, but it can be used for just about anything you want board specific- css, js, html, forms, ect...  including what you're asking for..

in your case, you'd want to plant either the script or a php include in the appropriate area in your index.template, and fill out the {whatever you want to inject} part with the title you want to use for the board...


Quote from: drewactual on February 20, 2018, 12:26:56 PM
it doesn't get a whole lot easier than this.   this is a variant of something i picked up here some time back, but can't recall where/who from.  All i did was intro the php include and external file, as well as multiple's by using the elseif operator.

you can use this however you see fit- and it works cleanly in many ways to include full out 'board sensitive' css or simple images... I use it to present a different header image for several boards... simply use a php include to a new file you're about to create... in that file:



<?php
if(( isset($_REQUEST['board']) && $_REQUEST['board'] == '1' ) || ( isset($board) && $board == '1' )) {
  echo 
'{whatever you want to inject}'; }

elseif(( isset(
$_REQUEST['board']) && $_REQUEST['board'] == '2' ) || ( isset($board) && $board == '2' )) {
  echo 
'{whatever you want to inject}'; }

elseif(( isset(
$_REQUEST['board']) && $_REQUEST['board'] == '3' ) || ( isset($board) && $board == '3' )) {
  echo 
'{whatever you want to inject}'; }

elseif(( isset(
$_REQUEST['board']) && $_REQUEST['board'] == '4' ) || ( isset($board) && $board == '4' )) {
  echo 
'{whatever you want to inject}'; }

elseif(( isset(
$_REQUEST['board']) && $_REQUEST['board'] == '5' ) || ( isset($board) && $board == '5' )) {
  echo 
'{whatever you want to inject}'; }
  
 else {
  echo 
'{whatever your base is}'; }
?>




the area {whatever you want to inject} is where your changes are offered.  you can use css, html, or even another php include if you want (such as you may if you're 'injecting' a large amount of info such as a big css or a big js)...

the area {whatever your base is} is what you want to appear (inject) on a 'standard' page- or left blank between the ' ' to not do anything.... it's there though, if you need it. 

the board numbers you should match up with the boards you intend to use this on.... i just numbered them 1, 2, 3, 4, and 5...

the function is injected on either your index.template, boardindex.template, or message.index template (adjusting accordingly) by a simple php include- such as:
include('url to the file you just made');

it's nice that it's an 'include' as it won't break anything if it doesn't work- such as jacked up code (if it's js or php you're 'injecting' that has a syntax error).  if it was 'require' (which you can use, but i wouldn't rec it) it would break the render if it tripped over itself.

at any rate, this is a useful little script to do (if i understand correctly) what you want to accomplish.  I hope you find purpose for it!



brettuk

Interesting, so, in theory i'd need to include the 'include' between the <title> tags?

Then it will call whatever is from the file?

That makes sense, however, I don't have a dedicated .php file to boards only?

If i put it into the index file, that'll apply to all pages?

Kindred

no no no no no... that is NOT how it should be done.

Seriously, look at the optimus brave mod.

But, If you absolutely feel the need to do it, don't do what drewactual said...       use the proper way to add content to the title
(can't recall off the top of my head, but it definitely is NOT the way that drewactual said)
Слaва
Украинi

Please do not PM, IM or Email me with support questions.  You will get better and faster responses in the support boards.  Thank you.

"Loki is not evil, although he is certainly not a force for good. Loki is... complicated."

drewactual

i'm thinking you'd want to use this in your 'board.index.php'....

place it right before the closing head tag:


include ('url-to-your-php-file'); 


and in your php file (one you will create) :

<?php
if(( isset($_REQUEST['board']) && $_REQUEST['board'] == '1' ) || ( isset($board) && $board == '1' )) {
  echo 
'<title>whatever you want board #1 titled</title>'; }

elseif(( isset(
$_REQUEST['board']) && $_REQUEST['board'] == '2' ) || ( isset($board) && $board == '2' )) {
  echo 
'<title>whatever you want board #2 titled</title>'; }

elseif(( isset(
$_REQUEST['board']) && $_REQUEST['board'] == '3' ) || ( isset($board) && $board == '3' )) {
  echo 
'<title>whatever you want board #3 titled</title>'; }

elseif(( isset(
$_REQUEST['board']) && $_REQUEST['board'] == '4' ) || ( isset($board) && $board == '4' )) {
  echo 
'<title>whatever you want board #41 titled</title>'; }

elseif(( isset(
$_REQUEST['board']) && $_REQUEST['board'] == '5' ) || ( isset($board) && $board == '5' )) {
  echo 
'<title>whatever you want board #5 titled</title>'; }
  
 else {
  echo 
'<title>whatever the base title is</title>'; }
?>



replace the board number with the board number you want to title, and the content in the 'echo' line... that easy. 

drewactual

it works... it's clean and error free both via SMF and server side... there is nothing dangerous or reckless about it. don't know why you don't approve, but..... it seems to be a trend that's unwarranted. 

now go ahead and edit as y'all usually do...

brettuk

That seems like such a good idea.

Kindred, why aren't you a fan, may I ask?

I have done this, but it doesn't seem to work, would this be compatible considering I am using pretty URL's?

Have added the following line to the index.template.php file, plonked it in with the rest.

Edit: that's the one in my custom theme folder.

<?php
/**
 * Simple Machines Forum (SMF)
 *
 * @package SMF
 * @author Simple Machines
 * @copyright 2011 Simple Machines
 * @license http://www.simplemachines.org/about/smf/license.php BSD
 *
 * @version 2.0
 */

/* This template is, perhaps, the most important template in the theme. It
contains the main template layer that displays the header and footer of
the forum, namely with main_above and main_below. It also contains the
menu sub template, which appropriately displays the menu; the init sub
template, which is there to set the theme up; (init can be missing.) and
the linktree sub template, which sorts out the link tree.

The init sub template should load any data and set any hardcoded options.

The main_above sub template is what is shown above the main content, and
should contain anything that should be shown up there.

The main_below sub template, conversely, is shown after the main content.
It should probably contain the copyright statement and some other things.

The linktree sub template should display the link tree, using the data
in the $context['linktree'] variable.

The menu sub template should display all the relevant buttons the user
wants and or needs.

For more information on the templating system, please see the site at:
http://www.simplemachines.org/
*/

/* This theme is a work of SMF Tricks Team. For more information please visit
http://www.smftricks.com/
This theme was adapted by Diego Andrés and its a Premium Theme.
Visit SMF Tricks for more Free Themes and Premium Themes.
LikeIPB is a Premium Adapted Theme.
*/

// Initialize the template... mainly little settings.
function template_init()
{
global $context$settings$options$txt;

/* Use images from default theme when using templates from the default theme?
if this is 'always', images from the default theme will be used.
if this is 'defaults', images from the default theme will only be used with default templates.
if this is 'never' or isn't set at all, images from the default theme will not be used. */
$settings['use_default_images'] = 'never';

/* What document type definition is being used? (for font size and other issues.)
'xhtml' for an XHTML 1.0 document type definition.
'html' for an HTML 4.01 document type definition. */
$settings['doctype'] = 'xhtml';

/* The version this template/theme is for.
This should probably be the version of SMF it was created for. */
$settings['theme_version'] = '2.0';

/* Set a setting that tells the theme that it can render the tabs. */
$settings['use_tabs'] = true;

/* Use plain buttons - as opposed to text buttons? */
$settings['use_buttons'] = true;

/* Show sticky and lock status separate from topic icons? */
$settings['separate_sticky_lock'] = true;

/* Does this theme use the strict doctype? */
$settings['strict_doctype'] = false;

/* Does this theme use post previews on the message index? */
$settings['message_index_preview'] = false;

/* Set the following variable to true if this theme requires the optional theme strings file to be loaded. */
$settings['require_theme_strings'] = true;
}

// The main sub template above the content.
function template_html_above()
{
global $context$settings$options$scripturl$txt$modSettings;

// Show right to left and the character set for ease of translating.
echo '<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"'
$context['right_to_left'] ? ' dir="rtl"' '''>
<head>'
;

include ('https://local-sexting.com/Themes/sexting/custom-page-titles.php'); 

echo '
<meta http-equiv="Content-Type" content="text/html; charset='
$context['character_set'], '" />
<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'], '</title>';

// The ?fin20 part of this link is just here to make sure browsers don't cache it wrongly.
echo '
<link rel="stylesheet" type="text/css" href="'
$settings['theme_url'], '/css/bootstrap.min.css" />
<link rel="stylesheet" type="text/css" href="'
$settings['theme_url'], '/css/responsive.css" />
<link rel="stylesheet" type="text/css" href="'
$settings['theme_url'], '/css/index'$context['theme_variant'], '.css?fin20" />
<link rel="stylesheet" type="text/css" href="'
$settings['theme_url'], '/css/buttonlistvariant.css?fin20" />';

// Some browsers need an extra stylesheet due to bugs/compatibility issues.
foreach (array('ie7''ie6''webkit') as $cssfix)
if ($context['browser']['is_' $cssfix])
echo '
<link rel="stylesheet" type="text/css" href="'
$settings['default_theme_url'], '/css/'$cssfix'.css" />';


Doesn't seem to be working unfortunately.

drewactual

you don't ever want to use the full URL... use the relative URL... for instance, if the php file you've created is on the same level as the theme you're using, simply use:


include ('custom-page-titles.php');


and move it below:

<link rel="stylesheet" type="text/css" href="', $settings['default_theme_url'], '/css/', $cssfix, '.css" />';


what i'm trying to achieve here is declaring the title AFTER it's already been declared by SMF, so you're not messing with the SMF code.  as it is, you have the include BEFORE the title declaration, which makes it not worky... it WILL work if it's after that line...

something else i do, for what it's worth, is remark away so i don't lose things... which would make the line:


// this next line is my custom board title mod so I don't lose it or look at it in coming years wondering what it is all about
include ('custom-page-titles.php');


or something to that effect...

an aside:  folks around here like using mod's- and i have nothing against MOST mods..  they are certainly useful and i appreciate all the effort made here to bring it all together... but i've also experience with bad mods- mods that don't work or that confuse the operation of the primary engine... and then dig in like a tick when you try to weed them (and their remnants) out... so for something as simple as what you're looking for, i'm thinking this is a-ok... but for larger mods that function far deeper in the coding, i wouldn't pave my own path... and maybe this is the reason i catch grief when i offer up simple little things such as this.  they DO pile up, so, a diary is helpful.  backups are helpful too... and some of these are an update away from having to be re-introduced... back to diary, huh?  but they work, and they're clean error and risk free. 

Kindred

i say again. No no no no no.

Doing it like that is THE WRONG WAY. There are existing codes in existence for adding and modifying the title tag (and other header stuff) doing it the way that drew suggests is the wrong way to do it.
Слaва
Украинi

Please do not PM, IM or Email me with support questions.  You will get better and faster responses in the support boards.  Thank you.

"Loki is not evil, although he is certainly not a force for good. Loki is... complicated."

brettuk

Thanks Drew, I can see why Kindred doesn't prefer this method, however, right now, I see no alternative method.

I appreciate your help!

So, it still isn't working.

So, my index.template.php is within my custom theme folder, in the same place as custom-page-titles.php.

The custom-page-titles.php contains:
<?php
if(( isset($_REQUEST['board']) && $_REQUEST['board'] == '1' ) || ( isset($board) && $board == '1' )) {
  echo 
'<title>whatever you want board #1 titled</title>'; }

elseif(( isset(
$_REQUEST['board']) && $_REQUEST['board'] == '2' ) || ( isset($board) && $board == '2' )) {
  echo 
'<title>whatever you want board #2 titled</title>'; }

elseif(( isset(
$_REQUEST['board']) && $_REQUEST['board'] == '3' ) || ( isset($board) && $board == '3' )) {
  echo 
'<title>whatever you want board #3 titled</title>'; }

elseif(( isset(
$_REQUEST['board']) && $_REQUEST['board'] == '4' ) || ( isset($board) && $board == '4' )) {
  echo 
'<title>whatever you want board #41 titled</title>'; }

elseif(( isset(
$_REQUEST['board']) && $_REQUEST['board'] == '5' ) || ( isset($board) && $board == '5' )) {
  echo 
'<title>whatever you want board #5 titled</title>'; }
  
 else {
  echo 
'<title>whatever the base title is</title>'; }
?>


Will this still work for pretty URL's?

Also, my index.template.php is now as follows:


// The main sub template above the content.
function template_html_above()
{
global $context, $settings, $options, $scripturl, $txt, $modSettings;

// Show right to left and the character set for ease of translating.
echo '<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"', $context['right_to_left'] ? ' dir="rtl"' : '', '>
<head>';

echo '
<meta http-equiv="Content-Type" content="text/html; charset=', $context['character_set'], '" />
<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'], '</title>';

// The ?fin20 part of this link is just here to make sure browsers don't cache it wrongly.
echo '
<link rel="stylesheet" type="text/css" href="', $settings['theme_url'], '/css/bootstrap.min.css" />
<link rel="stylesheet" type="text/css" href="', $settings['theme_url'], '/css/responsive.css" />
<link rel="stylesheet" type="text/css" href="', $settings['theme_url'], '/css/index', $context['theme_variant'], '.css?fin20" />
<link rel="stylesheet" type="text/css" href="', $settings['theme_url'], '/css/buttonlistvariant.css?fin20" />';

// Some browsers need an extra stylesheet due to bugs/compatibility issues.
foreach (array('ie7', 'ie6', 'webkit') as $cssfix)
if ($context['browser']['is_' . $cssfix])
echo '
<link rel="stylesheet" type="text/css" href="', $settings['default_theme_url'], '/css/', $cssfix, '.css" />';

// this next line is my custom board title mod so I don't lose it or look at it in coming years wondering what it is all about
include ('custom-page-titles.php');

// RTL languages require an additional stylesheet.
if ($context['right_to_left'])
echo '
<link rel="stylesheet" type="text/css" href="', $settings['theme_url'], '/css/rtl.css" />';


Not working unfortunately. :(

drewactual

you've got to adjust the board numbers and whatever information you want different about them... i.e. : (first two lines)

Quote
if(( isset($_REQUEST['board']) && $_REQUEST['board'] == '120' ) || ( isset($board) && $board == '120' )) {
  echo '<title>this is board 120s title now</title>'; }

elseif(( isset($_REQUEST['board']) && $_REQUEST['board'] == '130' ) || ( isset($board) && $board == '130' )) {
  echo '<title>this is what you want board 130 to be titled</title>'; }

see the red font above?  the board number is what SMF works off of- w/pretty URL's you MAY have to type out the name instead of the number...


brettuk

Ah - doesn't work. :( I put in 'general-discussion' as that's the board URL.

I don't want to use up to much of your time, but thanks anyway!

brettuk

I am still actively looking for a solution to this, plus, I think in some way or another it would benefit us all tremendously.

If anyone has any other ideas, please do share, it's greatly appreciated!

Steve

DO NOT pm me for support!

brettuk

I'm still on the lookout for a mod like this, all help is greatly appreciated.

I think everyone would benefit from something like this!

Kindred

Слaва
Украинi

Please do not PM, IM or Email me with support questions.  You will get better and faster responses in the support boards.  Thank you.

"Loki is not evil, although he is certainly not a force for good. Loki is... complicated."

brettuk

Quote from: Kindred on April 21, 2018, 05:37:30 PM
Did you install the Optimus brave mod

Yep, works a treat, I have solved this issue now, this thread can be deleted. :)

Advertisement: