- This topic has 12 replies, 3 voices, and was last updated 3 years, 4 months ago by
Ying.
-
AuthorPosts
-
November 23, 2022 at 9:29 am #2429550
Wayne
In another support topic the poster requested instruction to add a Facts Checked By field in addition to Author By in element block.
The response was:ou will need to create a Custom Field on your site.
You can use the WP core ones: https://wordpress.org/support/article/custom-fields/
Or a plugin like ACF to add them.You can then edit the Block Element you’re using to display your Post Meta, and include another Headline block to show your Custom Field by choosing the Post Meta option in the blocks dynamic data.
Is there a way to make a condition that the second author (who will not be posting or publishing their own articles – Just “Facts Checked By” headline) does not appear on the Element block if the Value field is empty in the page or post?
Thank you!
November 23, 2022 at 9:39 am #2429579David
StaffCustomer SupportHi there,
theres a couple of options, one of which would be to filter in the
Facts Checked bylabel to the headline block.1. Add this PHP Snippet:
add_filter( 'render_block', function( $block_content, $block ) { if ( !is_admin() && ! empty( $block['attrs']['className'] ) && 'fact-checker' === $block['attrs']['className'] ){ $block_content = '<span class="label">Facts Checked by <span>' . $block_content; } return $block_content; }, 10, 2 );2. Select the Block that is set to Display the second author and in its Advanced > Additional CSS class(es) add:
fact-checkerThe snippet about will then add:
<span class="label">Facts Checked by <span>in front of the author if it exists.November 23, 2022 at 9:56 am #2429630Wayne
I added the snippet to Snippets plugin and I get the following error:
Don’t Panic
The code snippet you are trying to save produced a fatal error on line 8:syntax error, unexpected ‘;’
The previous version of the snippet is unchanged, and the rest of this site should be functioning normally as before.Please use the back button in your browser to return to the previous page and try to fix the code error. If you prefer, you can close this page and discard the changes you just made. No changes will be made to this site.
This is a great solution if we can get working!
November 23, 2022 at 10:02 am #2429643David
StaffCustomer SupportOh damn, i am really really sorry about that. I updated the code above to add the missing
)https://generatepress.com/forums/topic/add-2nd-author-to-posts-and-pages/#post-2429579
November 23, 2022 at 11:01 am #2429748Wayne
Thanks! So it does display the label, but not the author name.
I have edited the element that is to display on the page. I have the custom field with the correct key and value. Site URL in the Private Info.
Also, I removed the author name in the Value field of Custom Field and saved, but the label was still shown, even though the Value was blank.
Am I missing something?
Thanks!
November 23, 2022 at 12:50 pm #2429924Ying
StaffCustomer SupportAlso, I removed the author name in the Value field of Custom Field and saved, but the label was still shown, even though the Value was blank.
I’m not seeing the value or the lable on the front end.
https://www.screencast.com/t/VDaEa3UoCan you add the author name back and let us take a look?
November 23, 2022 at 1:04 pm #2429939Wayne
I added that back in.
November 23, 2022 at 1:42 pm #2429985Ying
StaffCustomer SupportIf you don’t activate the custom function, does the value show on front end?
November 23, 2022 at 2:16 pm #2430022Wayne
For the custom field?
November 23, 2022 at 3:32 pm #2430101Ying
StaffCustomer SupportYes.
November 23, 2022 at 3:51 pm #2430117Wayne
I don’t have the custom field activated for other pages, but the label still shows.
November 23, 2022 at 3:59 pm #2430121Wayne
I am just going to take that off for now. Thanks.
November 24, 2022 at 3:34 pm #2431975Ying
StaffCustomer SupportI don’t have the custom field activated for other pages, but the label still shows.
The label is added to that headline output, so even if the value is empty, the label will still show.
A fix for this would be modifying David’s code a little bit, change
second_authorto your post meta field slug.add_filter( 'render_block', function( $block_content, $block ) { $second_author = get_post_meta( get_the_ID(), 'second_author', true ); if (!is_admin() && ! empty( $block['attrs']['className'] ) && 'medically_reviewed_by' === $block['attrs']['className'] && ! empty($second_author)){ $block_content = 'Medically reviewed by ' . $block_content; } return $block_content; }, 10, 2 ); -
AuthorPosts
- You must be logged in to reply to this topic.