STFS: Smart Title For SEO
For Elk 1.0.x & 1.1 Beta x.
Hook. No File Modification.
1. Please do your own backup though every installation is backed up automatically.
2. On default the "- Index" can be seen on the browser as forum index page title and this mod when enabled will remove it.
3. This mod will now also change your forum title from "page title" to "forum name - page title".
4. Upon its successful installation, you will be directed to addons page where you can enable/disable this mod.
5. There is nothing fancy about this mod as it is just a simple trick to boost a bit of SEO (at least IMO).
6. You can test it in lower version too as IMO it should work just fine. ;)
Thank you for using/testing it.
Yours friendly,
Abu Fahim Ismail.
BSD License. Feel free to modify accordingly but keep author's link if it is in there somewhere. ;)
(http://validator.w3.org/images/valid_icons/valid-xhtml10) (http://jigsaw.w3.org/css-validator/images/vcss)
(http://www.elkarte.net/community/index.php?action=dlattach;attach=1241;image)
(http://www.elkarte.net/community/index.php?action=dlattach;attach=4381;image)
#Change Logs@Version 1.1.2- Change version numbering to 1.0.x style.
- Fix settings to jquery to show other settings immeditely upon enable is checked.
@Version 1.1.1
- Added board option e.g. ElkArte - Board - Page Title.
- Added reverse option e.g. Page Title - Board - Elkarte.
@Version 1.0.9
- Restore location to /sources/addons.
@Version 1.0.8
- Make it work for 1.1 Beta 3.
@Version 1.0.7
- Standardizing files' location.
@Version 1.0.6
- Removing unnecessary code.
- Restructuring addon's directory and location.
@Version 1.0.5
- Rewriting the mod to fully use hooks
- Thus, no more file modifications.
@Version 1.0.4
- Fixing minor issues due to adding smart title.
@Version 1.0.3
- Add smart title instead of just removing index.
@Version 1.0.2
- Add option to turn it on and off.
@Version 1.0.1
- Minor fixes.
@Version 1.0.0
- Simply removes "- Index" from the forum title which can be seen in the browser.
Will this display the topic title or just the number of the topic. I have this installed and showing as /index.php/topic,2.0.html.
Meaning if your forum normally found in searches and browser title as ElkArte - Index, it will now be only ElkArte. Some of the pages like this topic page will be found in searches and browser title as STFS: Smart Title For SEO, it will now be ElkArte - STFS: Smart Title For SEO. It is only doing something like that not more. Not even as per your understanding above. Sorry. :)
Thank you for the reply, I just wanted to make it was working properly.
On SMF I have the Optimus Brave mod and the titles generated with Optimus Brave are:
{board_name} - {forum_name}
and for topics:
{topic_name} - {board_name} - {forum_name}
Is there a way to tweak this mod to have the same results?
thank you
Something like these two is possible:
{topic_name} - {forum_name}
{board_name} - {forum_name}
Open STFS.subs.php and simply change this code:
$title_new = '<title>' . (empty($context['page_title_html_safe']) ? $context['forum_name'] : $context['forum_name']. ' - ' . $context['page_title_html_safe']) . '</title>';
To:
$title_new = '<title>' . (empty($context['page_title_html_safe']) ? $context['forum_name'] : $context['page_title_html_safe'] . ' - ' . $context['forum_name']) . '</title>';
It works, but is there a simple way to include the board name of that topic? I'm asking this because I don't want to change all titles of my forum.
Thank you in advance
Possible but that have to defined inside the topic source file. I think it is in Display. Let me check first.
Ok. I got it now. Simply change the whole buffer code to this one:
function STFS_Titles(&$buffer)
{
global $modSettings, $context, $topic, $board_info;
if (isset($_REQUEST['xml']) || $context['current_action'] == 'printpage') return $buffer;
$stfs = array();
// Define the old and the new title
if (!empty($modSettings['stfs_enable'])) {
$title_old = '<title>' . $context['page_title_html_safe'] . '</title>';
$title_new = '<title>' . (empty($context['page_title_html_safe']) ? $context['forum_name'] : $context['page_title_html_safe']) . ' - ' . $context['forum_name']. '</title>';
$stfs[$title_old] = $title_new;
}
if (!empty($modSettings['stfs_enable']) && !empty($topic)) {
// Define the old and the new title
$title_old2 = '<title>' . $context['page_title_html_safe'] . '</title>';
$title_new2 = '<title>' . (empty($context['page_title_html_safe']) ? $context['forum_name'] : $context['page_title_html_safe']) . ' - ' . $board_info['name'] . ' - ' . $context['forum_name']. '</title>';
$stfs[$title_old2] = $title_new2;
}
// Now let's change the title, if we're allowed to
return str_replace(array_keys($stfs), array_values($stfs), $buffer);
}
I will consider to add the following option later in the mod:
1. Board name in topic title as per what you wanted.
2. Option for left to right or right to left. e.g.
Default - Forum Name - Board Name - Topic Name
Other - Topic Name - Board Name - Forum Name
I prefer forum name first as default since I normally search by typing site name followed by the search key.
Out of curiosity, did you already try using integrate_load_theme instead of a buffer replacement?
At that point you should be able to replace the content of $context['page_title_html_safe'] to whatever you want. ;)
Actually, I haven't. I will surely try that soon. Thanks for the tips
@emanuele.
Thank you
@ahrasis , it's working
I am testing this new approach with no success. Hook:
'integrate_load_theme' => 'STFS_Titles|SOURCEDIR/addons/STFS.subs.php',
Code:
function STFS_Titles()
{
global $modSettings, $context, $topic, $board_info;
// Load language(s)
loadLanguage('STFS');
// Redefine page title(s)
if (!empty($modSettings['stfs_enable'])) {
if (!empty($context['page_title_html_safe']) && !empty($topic))
$context['page_title_html_safe'] = $context['forum_name']. ' - ' . $board_info['name'] . ' - ' . $context['page_title_html_safe'];
if (!empty($context['page_title_html_safe']))
$context['page_title_html_safe'] = $context['forum_name']. ' - ' . $context['page_title_html_safe'];
else
$context['page_title_html_safe'] = $context['forum_name'];
}
}
Any ideas how to make this integrate_load_theme works?
The trial package attached.
Weeeeell... it's not that it has to work, it may have been a broken suggestion to begin with.
That one was really a suggestion in the sense "it may work or not, I'm not sure", sorry for not making it more clear... :-[
And reading better the code, it cannot work... I gave you a bad advise, I'm sorry. :(
But, that is something we should consider, the hooking is not really symmetric: there are lots of ways to hook the "starting" of ElkArte, but not a single one that allows to change stuff just before the template is sent out. <= improvements needed.
Hey! No worries. I like to try and test all the given codes though it may be broken or not working at all. That's how I learn most of the time - via errors. Keep tipping me. I like to have plenty of ideas in doing certain things rather than no or limited ideas in doing them. I have more fun learning that way.
Updated...
#Change Logs
@Version 1.3.1
- Removing unnecessary code.
- Restructuring addons directory and location.
Great attitude!
thumbsupsmileymissing
#Change Logs
@Version 1.3.2
- Standardizing files' location.
#Change Logs
@Version 1.3.3
- Make it work for 1.1 Beta 3.
#Change Logs
@Version 1.3.4
- Restored location back to /sources/addons.
- Fixed intgerate buffer error in PHP 7.
If using SimplePortal, the site title gets duplicated on main portal.
I can't link the site, as it's not accessible to others yet.
But, forum tab shows the title one time, just the portal page has it duplicated.
Also, suggestions for future updates:
1. Ability to have site title positioned by switch, to left or right of page title.
2. Ability to enter title want, into a field.
I am not so sure whether this addon can affect SimplePortal as it is only aimed to change the title in the browser for Elk. Normally, you will need to find the code that generates that title and change it OR maybe, just a maybe, you can add the code while creating the page i.e. inside that page code itself?
As per your first suggestion, the current one is already on the right, so this addon only change it to the left. I am not so sure about the second one though. Do you mean the ability to change the title of your forum? That should be done inside the forum ACP, don't you think? But, please, do clarify more if you mean other things per your suggestion.
1. Could add a selector, for those that have SimplePortal, that when checked, does not display the title on the main forum page. Normally, this would be the forum board listing, but with SP, it often is the main portal page. This is not a custom page you can edit through the SP pages function.
2. This addon adds the site title to page title, not just move from right to left. Without this addon, when I look at any page on the forum, it just tells the page title, and not the site title. So, a selector, would be nice to let the admin decide if they want site title to left or right of page title. (Yes, explained more in depth, for people not so familiar with the addon.)
Examples:
Unchecked: ElkArte Community - STFS: Smart Title For SEO
Checked: STFS: Smart Title For SEO - ElkArte Community
3. Sometimes, a site has a short name, which gets used for title, and a longer name that the logo would show. Like a couple of my sites, for example. The reason it's so, is that sometimes, where the forum shows the forum name, if it is long, it can look not so well. Luckily, some of that was fixed, by using the Home icon in linktree, instead of the whole forum name. However, there's still some other places.
My idea on the field, is for admins to maybe use a different name than the site's name is in settings. More a way to add to it, without adding to the official site name in settings.
Example: In settings: All Points Web Hosting
In custom field: All Points Web Hosting - Community Forum
Both, with page title before/after, depending on above switch.
1. I am not sure about SP as I am not using it.
2. Check and uncheck is there in the addon settings. If unchecked, the forum name will be at the end i.e default. If checked, the forum name will be at the first i.e. in contrast to default.
3. I will consider it. A field for it can be added in its settings.
#Change Logs@Version 1.3.5- Added board option e.g. ElkArte - Board - Page Title.
- Added reverse option e.g. Page Title - Board - Elkarte.
@Burke Knight, though not all, the addon has been updated to accommodate some of the ideas. I hope you like it.
(http://www.elkarte.net/community/index.php?action=dlattach;attach=4381;image)
#Change Logs
@Version 1.1.2
- Change version numbering to 1.0.x style.
- Fix settings to jquery to show other settings immeditely upon enable is checked.