Community Forums › Forums › Archived Forums › Design Tips and Tricks › Adding custom text in single post entry meta
Tagged: .post-info, entry-meta, monochrome pro
- This topic has 8 replies, 2 voices, and was last updated 7 years, 1 month ago by
danielleB.
-
AuthorPosts
-
March 13, 2018 at 8:53 am #217844
danielleB
ParticipantI'm creating a "press review" blog page to publish titles/summary from various articles on our services that appeared in news publications. My typical post entry meta includes the publication date and author (FPAdmin).
POST TITLE
PUBLISHED ON 2017-10-03 | FPAdmin
--Instead of FPAdmin, I'd like to include the name of the originating publication in the entry meta location next to the post-date, which means that each single post would output custom text in that area.
POST TITLE
PUBLISHED ON 2017-10-03 | New York Times
--Can anyone think of an easy way of doing this, if this is possible at all?
Many thanks,
Danielle
March 13, 2018 at 1:21 pm #217851danielleB
ParticipantI found this useful primer online, but it simply doesn't work for me. I'm using monochrome.pro. I tried the code in both the functions.php file and the single.php, but it returns an error.
I need to learn PHP.
🙁
Danielle
March 13, 2018 at 10:28 pm #217868Brad Dalton
ParticipantFilter the default post info and add it in there or create your own custom shortcode
March 13, 2018 at 10:34 pm #217869Brad Dalton
ParticipantSomething like this should get you started https://gist.github.com/braddalton/9bb2f4d76c99e4b5faae54b32d3c5625
March 19, 2018 at 9:50 am #218101danielleB
ParticipantThank you for this braddalton. I spent a lot of time trying it with the shortcode generator (great tool, by the way!) I'm learning a lot from the example you provided, but I can't quite get it to do what I need it to do.
Ideally, I'd like to add a shortcode at the beginning of the post: e.g., [publisher name="..."] that would return the appropriate credits in the entry meta. I would then use the Genesis 'quick edits' tool to add the shortcode to my posts. Using your example as a starting point, I tried to do this, but I can't get it to return variable content.
What am I missing?
Many thanks in advance for your help.
Danielle
March 19, 2018 at 9:53 am #218102Brad Dalton
ParticipantMarch 19, 2018 at 10:54 am #218104danielleB
ParticipantI added it to the theme's functions.php file, near the end, before the:
//* Customize the post meta function
add_filter( 'genesis_post_meta', 'sp_post_meta_filter' );
function sp_post_meta_filter($post_meta) {
if ( !is_page() ) {
$post_meta = '[post_categories before=": "] [post_tags before=": "]';
return $post_meta;
}}This is what the code looks like:
// Add Shortcode
function publisher_shortcode() {return '<span class="custom-entry-meta" itemprop="name"> | MRC Pontiac</span>';
}
add_shortcode( 'publisher', 'publisher_shortcode' );add_filter( 'genesis_post_info', 'sp_post_info_filter' );
function sp_post_info_filter($post_info) {
$post_info = '[post_date] by [post_author_posts_link] [post_comments] [post_edit] [publisher]';
return $post_info;
}Then, in the body of the post, I added the shortcode as follows: [publisher name="MRC Pontiac"] (MRC Pontiac was the publisher in this case, but not in every case.) This code returns "MRC Pontiac" in the entry.meta as well as the body of the post. What I need it to do, is return a variable entry in the entry.meta location only.
This is what it looks like:
By the way, I tried replacing MRC Pontiac (publisher name) with an empty ' ' in the code, but that doesn't work.
Danielle
Danielle
March 19, 2018 at 9:01 pm #218117Brad Dalton
ParticipantTo add the variable content use a custom field like
genesis_get_custom_field('key');
To add the custom field value to the post info, create a custom shortcode or filter the post_info.
March 20, 2018 at 9:04 am #218133danielleB
ParticipantThat worked! Thank you, Brad.
Danielle
-
AuthorPosts
- The topic ‘Adding custom text in single post entry meta’ is closed to new replies.