Adding custom PHP to the forum


Well-known member
How to add custom PHP to your forum is a question asked here and there. For a lot of people, me included, this is a critical feature to have. In my case I want to randomly rotate banners in a specific position. The display of a random banner on its own is easy enough with a little bit of PHP, but adding it to the forum is the next challenge.

There's quite often talk about plugins, hooks and listeners and other such sorcery and that point it does seem to be a lost cause if like me you can't program an add-on.

However just to put any other potential XenForo users minds at rest, I want to report that I have done this today without any problems. What I did was to make use of the excellent included advert templates to include the internet's best cheat: An iframe. This iframe pointed to the PHP file that generates a random banner every time it is called.

Job done, save for some custom PHP to float the banner to the right and to add some padding.

PS. I also did a "sponsors online" info block easy enough in the side bar. Just copied and pasted the staff on-line template code and changed the part where it checks for mod/admin to instead check for membership of a specific usergroup as per Brogan's FAQ. Job done.