Archived topic
Missing icon after adding in dynamic meta
9 replies · Started by lewis on June 30, 2022
Hi there, I have added in the dynamic attributes for the icons for email as per the GP video. However, after saving, the email icon has no disappeared on the post. Here are the settings I currently have. https://imgur.com/a/V2zVxkM
Hi Lewis,
Try using user_email as the meta field name.
Kindly let us know how it goes.
Thanks. Email icon is now showing up, but does not seem to be dynamic, just opens to "gmail.com". Thanks
Yes, that’s the default behavior if you set an email as the dynamic link type. It goes to the domain of the email.
Hope this clarifies!
Oh ok. How do you make it so the email is actually pulled from the author profile? e.g. shelly@gmail.com. Also, what is the dynamic prompt for a link to the authors website? Thanks
To clarify, do you mean the email is copied when the button is clicked? If so, you would need Javascript for that.
The meta field name for the website is user_url.
You’ll find other author meta field names here: https://developer.wordpress.org/reference/functions/get_the_author_meta/#description
Hope this clarifies.
Hi there,
To clarify, when clicking on the email icon button, instead of being dynamic and linking to the email that is associated to the author profile page (e.g. shelly@gmail.com), all posts for all authors are linking to gmail.com instead of being dynamic. Thanks
Are you wanting the Block to link to the Author’s archive page? If that’s what you’re going for, you should set the Dynamic Link type to Author Archive instead.
Hope this clarifies!
Hi Fernando, just made this quick vid to clarify. Thanks
Yes, that’s the default behavior.
You would need custom code to alter the href for the link to behave in the way you want it to.
For instance, try adding my-email to the Classlist of the Block. Example: https://share.getcloudapp.com/5zur92b0
Then, add this PHP snippet:
function db_rerender_email_url( $block_content, $block ) {
if(!is_admin()){
if ( ! empty( $block['attrs']['className'] ) && 'my-email' === $block['attrs']['className'] ) {
$my_search='href="';
$my_replace='href="mailto:';
$new_content = str_replace($my_search, $my_replace, $block_content);
return $new_content;
}
}
return $block_content;
}
add_filter( 'render_block', 'db_rerender_email_url', 10, 2 );
This code as modifies the href to add mailto:
Adding PHP reference: https://docs.generatepress.com/article/adding-php/#code-snippets
Hope this helps!