Site logo

[Resolved] Custom link on dynamic text type

Home Forums Support [Resolved] Custom link on dynamic text type

Home Forums Support Custom link on dynamic text type

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #2531010
    Ioana

    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/

    ScreenShot

    #2531038
    Fernando
    Customer Support

    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/

    #2531052
    Ioana

    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

    #2531077
    Fernando
    Customer Support

    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.

Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.