Archived topic
Custom link on dynamic text type
3 replies · Started by Ioana on February 12, 2023
Hello!
I want to create a new function on Dynamic text type as a "custom link".
For example: Change the author link with http://www.site.com/about-us/
To clarify,
Are you wanting to add a Post Meta link?
If so, you can use a plugin like Advanced Custom Fields to do so. Reference: https://www.advancedcustomfields.com/resources/getting-started-with-acf/
I want to add a custom link By Author (/about-us/) (not meta). I don't use ACF.
HTML Now:
<div class="gb-headline gb-headline-3fa6984b gb-headline-text">by <a>https://domain.com/author/ioana/">Ioana</a></div>
I want to change with:
<div class="gb-headline gb-headline-3fa6984b gb-headline-text">by <a>https://domain.com/about-me/">Ioana</a></div>
I want to add the function "Custom Link" in the editor.
Function to add: Screenshot
1. Add replace-url to the class list of the Headline Block.
Adding Custom Classes: https://wordpress.com/support/wordpress-editor/adding-additional-css-classes-to-blocks/
Then, add this snippet:
add_filter( 'generate_dynamic_element_url', function( $url, $link_type, $source, $block ){
if ( ! empty( $block['attrs']['className'] ) && strpos( $block['attrs']['className'], 'replace-url' ) !== false ) {
$url = 'https://google.com';
}
return $url;
},15,4);
Adding PHP: https://docs.generatepress.com/article/adding-php/#code-snippets
Replace https://google.com with your link.