Hey guys, first off I played around with shortcodes, but they aren’t working. I might have a some conflict (tried for hours to find it) but for now, it’s not an option. But the following works in allowing my commenters to use the [img] tags in their comments (which get replaced to the html equivalents) and I’d like to expand on it.
Please no plugins!
What I’d like to do is amend the following bit of code to allow [b], [i], and [code] (both lower and upper case entries) to spit out the html equivalents so my comments can just use the standard bbcodes when they comment, very much how the current function works:
function embed_images($content) {
$content = preg_replace('/[img=?]*(.*?)([/img)?]/ei', '"<img src="$1" alt="" . basename("$1") . "" />"', $content);
return $content;
}
add_filter('comment_text', 'embed_images');
I’ve tried and tried but can’t get it to work. Any coding help would be greatly appreciate. Thanks guys.
Edit: Okay guys, got it working. Does this look okay? I mean it works, but how is the code… decent?
function embed_bold($content) {
$content = preg_replace('/[b]*(.*?)([/b)?]/ei', '"<strong>$1</strong>"', $content);
return $content;
}
add_filter('comment_text', 'embed_bold');
I once wrote a blog post about using regex for bbcodes. Most recommend using a PHP extension specifically built for BBCodes however. Here is the article:
http://www.spotlesswebdesign.com/blog.php?id=12
replace with
Okay dqhendricks, based on your coding convention, I’ve merged all bbcodes into one function. Any serious coding violations, or does it look good?
Thanks again for all your help.