Add piece of custom code to index

Started by Kara_Mel, June 01, 2020, 04:28:47 PM

Previous topic - Next topic

Kara_Mel

I have a piece of self-written PHP code, which echo in form of HTML table I would like to display somewhere at the top of all forum-related pages. E.g. if talk about this default forum schema - somewhere near the "Hello Username". However I have never encountered SMF before, so have no full idea where to add something like require('custom_code.php');. So, I would like to know in which file(s) should be included a reference to my code.

Arantor

You'd normally add in the index.template.php file for the theme you're using.

Kara_Mel

So, if I add require('custom_code.php'); at the end of the section with greetings  ($context['user']['is_logged']) {} - it should work and forum won't go down? :)

Arantor

Well... assuming you correctly add it to the PHP of the page, and wrap it inside the if statement correctly (if that's what you want), it should be fine.

This also assumes your custom code doesn't try to do anything funky and won't otherwise break itself.

Kara_Mel


Doug Heffernan

Quote from: Kara_Mel on June 01, 2020, 04:42:48 PM
So, if I add require('custom_code.php'); at the end of the section with greetings  ($context['user']['is_logged']) {} - it should work and forum won't go down? :)

As mentioned above, if it is done properly then there will be no errors in the forum. However, just to be sure make first a backup of the file that you will edit. Or better yet, try it first in a test/dev forum till you get it right and then apply the changes at your live forum.

Advertisement: