Home / Archive / MemberPress: Add Author Custom Bio Shortcode
Duplicate Snippet

Embed Snippet on Your Site

MemberPress: Add Author Custom Bio Shortcode

Add the [mpcs-author-custom-bio slug="mepr_short_bio"] shortcode to a post, page, or course. The shortcode will display the value of the mepr_short_bio custom field of the post, page, or course author. The mepr_short_bio parameter must be edited to use the slug of your custom field.

Code Preview
php
<?php
function mpcs_author_custom_bio_shortcode( $atts ) {
	if( !isset( $atts['slug'] ) || empty( $atts['slug'] ) ) { return; }
	
	global $post;
	$field = get_user_meta( $post->post_author, $atts['slug'], true );
	if( empty( $field ) ) { return; }
	
	return '<p>' . sanitize_text_field( $field ) . '</p>';
};
add_shortcode( 'mpcs-author-custom-bio', 'mpcs_author_custom_bio_shortcode' );

Comments

Add a Comment