If you're looking to hire a development firm to build you a mobile or web app, this Quick Reference Guide is a must-have.
If you’re a WordPress developer, creating custom themes from scratch, you’ve been there before. You need to use custom fields in order to make for an easy content management experience on the admin side, but pulling content from custom fields on certain posts and pages into other page templates can be quite a tricky process – and keeping formatting is even harder.
Well, it was harder.
WordPress, out-of-the-box, strips formatting on content when pulling from custom fields with ‘get_post_meta’. This isn’t good – custom fields are super handy for complex page layouts.
<?php
/* @Recreate the default filters on the_content so we can pull formated content with get_post_meta
-------------------------------------------------------------- */
add_filter( 'meta_content', 'wptexturize' );
add_filter( 'meta_content', 'convert_smilies' );
add_filter( 'meta_content', 'convert_chars' );
add_filter( 'meta_content', 'wpautop' );
add_filter( 'meta_content', 'shortcode_unautop' );
add_filter( 'meta_content', 'prepend_attachment' );
?>
See the Pen ubhsk by Keyfer Mathewson (@keyfermath) on CodePen.
<?php
$unformatted_content = get_post_meta($postID, 'custom-field-name', true);
?>
See the Pen ejIoC by Keyfer Mathewson (@keyfermath) on CodePen.
<?php
$formatted_content = apply_filters('meta_content', $unformatted_content);
?>
See the Pen oeFvB by Keyfer Mathewson (@keyfermath) on CodePen.
If you have a WordPress problem you’d like an article on, let us know on Twitter!