Adding Custom Information to Entry Meta in Genesis

On single post details I shall add some custom information at entry meta bar. Site is using the Genesis Framework. So I am using the Advanced Custom Field plugin for custom data. For example, I shall display the website link and hash tag. Therefore I created two custom fields with ACF plugin for post type only. See the attached screenshot for custom field settings.

Navigate to Post’s Add/Edit screen and you will get extra meta box section below WP Editor box. Enter website link and hashtag there and save the post.

Now open the functions.php file of your Genesis child theme and add this PHP snippets:

add_filter( 'genesis_post_info', 'pc_edit_post_info' );
function pc_edit_post_info( $post_info ) {

	if( is_singular( 'post' ) ) {
		$web = get_post_meta( get_the_ID(), 'site_url', true );
		$hashtag = get_post_meta( get_the_ID(), 'hash_tag', true );

		if( ! empty( $web ) ) {
			$post_info .= sprintf( '%s', trim( $web ) );
		}

		if( ! empty( $hashtag ) ) {
			$post_info .= sprintf( '%s', trim( $hashtag ) );
		}
	}

	return $post_info;
}

is_singular( ‘post’ ) conditional tag is checking that user is viewing the single post details page. get_post_meta() function retrieve the custom field data from postmeta table. get_the_ID() is returning the current post ID. If data is available then I am appending these custom data with post info content.

This site uses cookies to offer you a better browsing experience. By browsing this website, you agree to our use of cookies.