Needed a way to display meta field info in a post as part of a site rebuild I’m working on.
The meta shortcode plugin adds a short code to WordPress that will display the contents of a meta field if it exists, and optionally something else if it doesn’t.
You can get the plugin from the WordPress plugin library.
Use the [ metafield ] shortcode, without the spaces, where you want the info to appear.
The following attributes are available.
- field – The name of the field to use. This is the only required attribute.
- before – Text or HTML to display before the meta field. Defaults to nothing for single meta values or <ul> for cases where there are multiple values for a meta field.
- after – Text or HTML to display after the meta field. Same defaults as before except it closes the list.
- sorted – If there are multiple values for a meta key, setting this to true will sort them alphabetically. Setting to false or leaving blank will output in the order entered in WordPress. This attribute has no effect if the meta key only has a single value.
- empty – Displayed when the meta key is empty or not found. Defaults to empty which means nothing will be displayed if the key isn’t found.