Return vs Echo

I recently made a mistake that I wanted to share. It might save you a headache.

When making a short code make sure to return a value and not just echo it out.

The echo will display content, but it’s placement will be off, which is what gave me my headache.

Instead, put your echo’s in a string then return it.

//incorrect
function foobar_func( $atts ){
 echo "foo and bar";
}
add_shortcode( 'foobar', 'foobar_func' );
//correct
function foobar_func( $atts ){
 return "foo and bar";
}
add_shortcode( 'foobar', 'foobar_func' );
Posted in Snippet, Web Development

Add TinyMC to the Excerpt

Found myself needing to add the TinyMC editor to the excerpt section. Found this handy code snippet.

http://wpsnipp.com/index.php/excerpt/enable-tinymce-editor-for-post-the_excerpt/

Posted in Snippet
In Archive