This plugin came about while working on another site where I needed a way to insert information from a custom field, but didn’t want to have to manually insert it via the theme files.
After uploading and activating the meta shortcode plugin you will have a new shortcode to use in your WordPress posts that will display the contents of a custom field, or optionally another message if the field doesn’t contain information.
Use the [metafield] shortcode in your content where you want the information to appear.
The following shortcode attributes are available.
- field – The custom 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 in the custom field.
- after – Text or HTML to display after the meta field. Defaults to nothing for single meta values or </ul> for cases where there are multiple values in the custom field.
- 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 custom field only has one value.
- empty – Displayed when the custom field is empty or not found. Defaults to an empty string which means nothing will be found if the key isn’t found.