Created
June 16, 2023 21:23
-
-
Save alanef/87300ec1f8c46a040dee87e7faa44620 to your computer and use it in GitHub Desktop.
Get custom field shortcode
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
* Plugin Name: Get Custom Field Shortcode | |
* Description: Display custom fields in your WordPress site | |
* Version: 1.0 | |
*/ | |
/** | |
* Get Custom Field Shortcode | |
* | |
* @param array $atts | |
* | |
* @return string | |
* | |
* usage: [get_custom_field custom_field="my_custom_field"] | |
*/ | |
add_shortcode( 'get_custom_field', function( $atts) { | |
$atts = shortcode_atts( array( | |
'custom_ield' => '', | |
), $atts, 'get_custom_field' ); | |
$custom_field = $atts['custom_field']; | |
$custom_field_value = get_post_meta( get_the_ID(), $custom_field, true ); | |
return wp_kses_post($custom_field_value); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment