phpBB3: In-Line Code

One of the best features that was added in phpBB3 when it came out was the ability to add custom BBCodes for use in forum posts. It made it possible to include abilities like text effects, embedding videos and other things without having to use mods. It’s one of the best features in phpBB, and it’s also one reason why I prefer it over competitors like SMF (which, as far as I know, don’t even have this ability in the upcoming 2.1 release).

If discussions in your board center around programming, it’s probably worthwhile to you for posters to have the ability to bring attention to certain words or characters in their posts, particularly related to code, without the need to isolate it inside of a <div> the way the standard BBCode block does. Fortunately, it's extremely easy to do.

Assuming you're familiar with the phpBB ACP, navigate to the POSTING -> BBCodes section, and select Add a new BBCode.

You can use whatever you wish for the actual BBCode, but I chose iCode to keep it relatively simple and similar to the standard Code BBCode option.

For the BBCode usage section, define the usage as shown (with the exception of using a different BBCode name):


Then under HTML replacement, put the following:

<code style="background-color:#FFF; color:#2E8B57; border:1px solid #C9D2D8; padding: 0 1px; font:0.9em/1.3em Monaco,'Andale Mono','Courier New',Courier,mono;">{TEXT}</code>

Lastly, define a help-line, if you wish to have one, and select whether or not you want the button for the BBCode displayed on the posting page. Then just hit Submit, and you're done!

Here is how the text placed within the BBCode will look in a post (using prosilver):

phpBB3 In-Line BBCode

If you're using a different style other than prosilver, it may be worthwhile to define CSS style elements inside the theme stylesheets for each style so that the in-line code will look different depending on the style your forum users are using. In that case, you would want to use something like the following for your HTML usage section for the BBCode:

<code class="inline-code">{TEXT}</code>

After all, it would be more appropriate for this BBCode to style text in the post to follow the way it does in the regular Code block, that way people know what they're looking at.

Just remember that text placed inside of custom BBCodes is still parsed the way all other text in the post is, and so using other BBCodes within this one will result in the effects of those other BBCodes still being applied rather than showing them in an un-parsed format the way the standard Code BBCode tag does.