phpBB – add a link in the menu?

Probably every administrator of a phpBB forum sooner or later adds additional links at the top. So it’s time for me to ask – how do I add a link at the top of the forum (in the header) of the phpBB forum next to FAQ, Users, Exit?
Seemed like a pretty simple task, but there’s no way around it. phpBB uses variables, and this elementary for most engines refinement requires some knowledge.
I’ve read the support forums and found that 90% of administrators (judging by the support forums) prescribe the link in a rather barbaric way –

The link itself is inserted through the file includes/functions.php , then write the link inscription in language/ru/common.php and finally hook it in the template file.
What is bad about this option? And here’s what – with this approach is more difficult to put mods and update the engine, because in fact you change the core forum. It is very likely that when you upgrade to a new version of the forum (or heaven forbid, a branch), added functionality will fly off, and you will have to dopilivate all over again.

An adequate solution to this problem:

There is something called the Hook system in phpBB that allows you to create add-ons outside of the forum core. I won’t get into specifics, you can read more in docs/hook_system.html
So, to add a link via a hook, you need:
1) All hooks are stored in the includes/hooks folder . Let’s create there hook_links.php file with the following contents:

function gen_links()
global $phpbb_root_path, $phpEx, $template, $user;
‘U_NEW_LINK’ => append_sid(“{$phpbb_root_path}link.$phpEx”)

$phpbb_hook->register(array(‘template’, ‘display’), ‘gen_links’);

Of this whole venegret, you need to change the line 'U_NEW_LINK' => append_sid("{$phpbb_root_path}link.$phpEx"), где U_NEW_LINK – variable name, and append_sid – is a function that returns a string containing the URL with the session ID.

If you want to insert a link to an internal page, such as a topic (I made a link to the rules of the forum), this line will look something like this:

‘U_NEW_PRAVILA’    => append_sid($phpbb_root_path.’viewtopic.’.$phpEx, ‘f=21&t=41’)

If you want to insert an external link, use this construction:

‘U_NEW_PRAVILA’    => append_sid(“”)

2) Now we need to create a language file, in which we will write the text of the links. Use the folder language/en/mods , where we create links.php with the following contents:

$lang = array_merge($lang, array(
‘NEW_LINK’ => ‘Click me’

In my case, I was referencing forum rules, so the variable looked like this:

‘NEW_PRAVILA’    => ‘Forum rules’

3) Now use our variables in the template file overall_header.html. This is easy to do in the admin panel: Styles – Templates – Change and select our file.

Now search for “FAQ” and similarly insert the following line:

<li><a href=”{U_NEW_PRAVILA}”>{L_NEW_PRAVILA}</a></li>

For the li tag, you can specify the class=”…” property, where you can insert an icon, such as icon-subscribe, instead of a triplet.

4) Now clear the cache (you can do it on the main admin page), and you will see your coveted button in phpBB (smiley)

Have a nice day!

This entry was posted in phpBB (en). Bookmark the permalink.

Leave a Reply

🇬🇧 Attention! Comments with URLs are not allowed.
🇷🇺 Комментарии со ссылками удаляются автоматически.