Archived topic
Creating a custom byline
16 replies · Started by Craig on December 26, 2017
Hello,
I've created a custom taxonomy called "writer" and would like to display that for my post meta rather than WP author.
Should I...
1. Hide the author meta via customizer and insert my custom byline via hook?
2. Edit my child theme version of post-meta.php?
Thanks for any suggestions!
I would go for #1.
Then you can hook your own code in using this hook: https://docs.generatepress.com/article/generate_after_entry_title/
Let me know if you need more info :)
Hi,
I'm trying to display an ACF Pro field (read_time) as meta, only on post archive pages, instead of the post date and author.
Here is the code for display the custom field, please can you help me to write the full snippets?
the_field('read_time');
You would do something like this:
add_action( 'generate_after_entry_title', 'tu_custom_byline' );
function tu_custom_byline() {
if ( function_exists( 'the_field' ) && is_archive() ) {
the_field( 'read_time' );
}
}
Tom...just a quick followup to my original question. Your new(ish) custom page headers are awesome. I hid post meta via customizer and created a page header using the {{post_terms.taxonomy}} template tag to pull in my custom taxonomy. Works great!
Awesome! Glad you like it :)
The Page Header will also automatically remove the post meta if it's set in the Page Header on that page, so you can keep it elsewhere instead of hiding it globally in the Customizer.
Just noticed that...very slick! Props mate.
Hi Tom,
it works very well, thanks a lot, but it needs a little finishing touch: how to add some text before the custom field, like "Read Time:" and after "Minutes".
Also is it possible to show the custom field also in the main blog page (it seems that is not considered an archive page) ?
Try this:
add_action( 'generate_after_entry_title', 'tu_custom_byline' );
function tu_custom_byline() {
if ( function_exists( 'the_field' ) && ! is_singular() ) {
echo 'Read Time: ';
the_field( 'read_time' );
echo ' Minutes';
}
}
Works great.
Thanks again!
You're welcome :)
Hi Tom,
a little follow up with that: I would like to show this custom field on the same line with post date and post author as the first element (now it appears in a different line below the post date and author).
I tried to put the function inside a entry-meta div but although it takes the css style of the other metas is still on another line as a second entry-meta div.
Please can you help me to show this custom field inline with other metas?
Any chance you can link me to the page?
Sorry, I'm working offline but I can share with you a screenshot: https://www.dropbox.com/s/4hijca110wfvp9m/Articoli.jpg?dl=0 and this is the code I'm using for dislaying the ACF custom field for the new meta:
<?php if ( function_exists( 'the_field' ) && ! is_singular() ) : ?>
<div class="entry-meta">
<?php echo 'Tempo di lettura: ';
the_field( 'read_time' );
echo ' min'; ?>
</div>
<?php endif; ?>
As you can see I tried to wrap the function inside the entry-meta div but this simply create a new entry-meta div, instead I would like to display the new meta on a single line toegether with posta date and author.
It's really hard to tell without inspecting the code, but you could try this:
.entry-meta {
display: inline-block;
}