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:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
<?php //* Do not include this line 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( '<span class="web-link">%s</span>', trim( $web ) ); } if( ! empty( $hashtag ) ) { $post_info .= sprintf( '<span class="post-hashtag">%s</span>', 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.
John says
Will this code work for a Custom Post Type with custom taxonomies?