Site logo

[Support request] Image Block – Dynamic data > Link new tab (target blank)

Home Forums Support [Support request] Image Block – Dynamic data > Link new tab (target blank)

Home Forums Support Image Block – Dynamic data > Link new tab (target blank)

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #2469034
    akal

    Hi, could you please consider adding the ability to check “open in a new tab” (target=’_blank’) when “Enable Dynamic Data” + “Link Source” is checked ?
    Screen example

    #2469041
    Fernando
    Customer Support

    Hi Akal,

    For feature requests, you may raise a topic here: https://community.generateblocks.com/c/feature-requests/6

    As for the current solution for this, you can add open-in-new-tab-cu to the class list of the Block that’s a link.

    https://wordpress.com/support/wordpress-editor/adding-additional-css-classes-to-blocks/

    Then, add this snippet:

    function db_rerender_url_new_tab( $block_content, $block ) {
    	if(!is_admin() && ! empty( $block['attrs']['className'] ) && strpos( $block['attrs']['className'], 'open-in-new-tab-cu' ) !== false  ) {
    			$my_search='href="';
    			$my_replace='target="_blank" href="';
    			$new_content = str_replace($my_search, $my_replace, $block_content);
    			return $new_content;
    	}
        return $block_content;
    }
     
    add_filter( 'render_block', 'db_rerender_url_new_tab', 10, 2 );

    Adding PHP: https://docs.generatepress.com/article/adding-php/#code-snippets

    #2469057
    akal

    Many thank for fast reply, working as expected ^^

    #2469058
    Fernando
    Customer Support

    You’re welcome, Akal!

    #2492255
    Lee

    Thanks for the solution.

    #2492258
    Fernando
    Customer Support

    You’re welcome, Lee!

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