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;
}
Bill Erickson

Bill Erickson is the co-founder and lead developer at CultivateWP, a WordPress agency focusing on high performance sites for web publishers.

About Me
Ready to upgrade your website?

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

Let's Talk