Hi there,
I am using Advanced Custom Fields in my site to make custom post types in a few areas.
The issue that I am having is that I have setup a custom field within my blog posts named “story contributor”. What I want to do is have it replace the default post author coming up as the person who published the blog post (sort of like a guest author). So I went through the GP documentation about using filters:
https://docs.generatepress.com/article/generate_post_author_output/ (generate_post_author_output)
and came up with the following code to detect if poster put the guest contributor name in the acf field and have it overwrite on the post meta:
/* Filter to modify the post metadata (author) */
add_filter( 'generate_post_author_output', function( $output ) {
if (get_field('story_contributor')) :
$story_author = the_field('story_contributor');
return ' | by <i class="fa fa-user-circle" aria-hidden="true"></i>' . $story_author;
else :
return ' | <i class="fa fa-user-circle" aria-hidden="true"></i> ' . $output;
endif;
} );
However, the front end is coming out very strange, whereby the “story author” comes out in front of the fontawesome icon and other precursor text, like this:
July 18, 2020 Jeff Spears | by [font-icon]
How can I amend the code to make sure the custom filter prints out in the right order?
The default behaviour works fine as expected (when no story contributor is inserted into blog post).