Skip to content

How to wrap a SMF forum in WordPress

After spending the better part of yesterday getting a forum setup with the same layout as its parent WordPress site I thought I’d share a couple of tips along the way.

And I picked a less efficient way, including wp-blog-header.php in the forum code, because it was far easier. At some point I may go back and cache the WordPress pieces on the blog side and use those cache files on the SMF side, at which point none of this would be necessary. But for now it’s working.

Both WordPress and SMF have an is_admin() function. One has to be renamed. Well, I suppose you could rewrite one to cover both functions and remove the other. But I went for easy. I did a recursive replacement for all occurrences of is_admin in the SMF directory changing everything found to isAdmin and it seems to be working fine.

Include the wp-blog-header.php file. This has to be done somewhere in the SMF code, not in your theme. Best guess is it’s an issue of variable scope. The theme files are probably included inside a function somewhere so any of the WP variables and classes would have to be tagged global in that function. Or you could just include it at the top of the main SMF index.php file, which is what I did and it worked without a hitch.

Theme files
Use if (defined(‘SMF’)) {} in your WordPress themes if you have stuff you only want displayed on the forum. For mine I wanted a login form, forum menu, and forum stats to show up in the sidebar. Of course these don’t make sense on the blog so I wrapped that code in an if.

Switching between databases
And the one that took the most tinkering… You may have to change the database back and forth. For mine WordPress loaded its database and created the header. SMF then took over and built the forum part of the page. But I was having problems getting the page list, archives, etc to show up on the sidebar which happens in code after the forum code. What I did was at the end of the if(defined(‘SMF’)) {} block in the sidebar I put mysql_select_db(DB_NAME) which set the database back to the WordPress database. I’m pretty sure I could have also put both sets of tables in the same DB to get around this, but my forum has been running for a while and I didn’t want to deal with exporting and importing all that data.

See it in action
You can see the results at the ProofBuddy support forums.

Published inBloggingProgramming


  1. is there a way to wrap wordpress in smf?

  2. I’m sure there is, but my guess is it would be messier.

  3. Avs Avs

    Hi Ryan,
    I really like the simplicity of the SMF theme you are using on your site you have done this on – is it something you would be willing to share.

    I am wanting to wrap a forum in a wordpress site and something so plain and simple would be great.
    Any help would be much appreciated.
    Thanks :)

  4. TriXia TriXia

    Nice post, just what I’m trying to do. Having problem with the include(); part, did you put the include(); in top of forum/index.php? I’m getting errors from line require_once($sourcedir . ‘/QueryString.php’); if I do that.

    • I don’t remember off the top of my head. It was in one of the core files though. Couldn’t get it to work by including in the theme files.

Leave a Reply

Your email address will not be published. Required fields are marked *