Are you a GenerateCustomer?

Do you have an active GP Premium or GenerateBlocks Pro license key?

Create a GenerateSupport account for GeneratePress and GenerateBlocks support in one dedicated place.

Create an account
Already have a GenerateSupport account? Login

Just browsing?

Feel free to browse the forums. Support for our free versions is provided on WordPress.org (GeneratePress, GenerateBlocks).

Want to become a premium user? Learn more below.

Allow target as custom attribute for Blocks

  • Hi Support,

    When using dynamic data feature with Link on Headline Block for example, I am not able to add target=”_blank” as an attribute or activate this option. Please allow target as custom attribute.

    Thanks

  • Hi there,

    it is on our list, for now you can do it with some PHP.
    For example:

    
    add_filter( 'render_block', function( $block_content, $block ) {
    	if ( ! is_admin() && ! empty( $block['attrs']['className'] ) && strpos( $block['attrs']['className'], 'open-new-tab' ) !== 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;
    }, 10, 2 );
    

    Once added select the Headline block and in Advanced > Additional CSS Classes add: open-new-tab

  • Hi David,

    Sorry for my late reply. Thanks for your update and the provided code.
    Appreciate your support.

    Best

  • You’re welcome!

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