Simple HTML Formatting

Sometimes when working with metaboxes, you don’t want a full WYSIWYG but do want some basic formatting, like <strong> and line breaks.

Use the following filters to make *this* into <strong>this</strong> and | into <br />

<?php
/**
* Strong Markdown
*
*/
function ea_strong_markdown( $text ) {
$strong_character = '*';
if( 2 == substr_count( $text, $strong_character ) ) {
$text = substr_replace( $text, '<strong>', strpos( $text, $strong_character ), strlen( $strong_character ) );
$text = substr_replace( $text, '</strong>', strrpos( $text, $strong_character ), strlen( $strong_character ) );
}
return $text;
}
/**
* Line Break Markdown
*
*/
function ea_br_markdown( $text ) {
$br_character = '|';
$text = str_replace( $br_character, '<br />', $text );
return $text;
}
view raw functions.php hosted with ❤ by GitHub
Bill Erickson

Bill Erickson is a freelance WordPress developer and a contributing developer to the Genesis framework. For the past 14 years he has worked with attorneys, publishers, corporations, and non-profits, building custom websites tailored to their needs and goals.

Ready to upgrade your website?

I build custom WordPress websites that look great and are easy to manage.

Let's Talk