Site logo

Archived topic

Custom link on dynamic text type

3 replies · Started by Ioana on February 12, 2023

Viewing posts 1–4 of 4

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.

This archived topic is closed to new replies.