-
waynewil
Hi,
I have a set of product images displayed in my right sidebar. The associated URLs are stored in an ACF custom field associated with post. I select these URLs as links via Link Source = Post Meta, Post Meta Field = the ACF field that stores the link. Everything works great, but I don’t see any option to open the links in a new tab.
How do I address this?
Wayne
-
Alvind
Hi there,
Can I see the page by any chance?
-
waynewil
Sure. Main page, right side: https://rjsilverauthor.com/
-
Alvind
Select the Image block in the Query Loop, then under Advanced > Additional CSS Class(es) add this:
img-open-new-tab
After that add this PHP snippet:
add_filter( 'render_block', function( $block_content, $block ) { if ( ! is_admin() && ! empty( $block['attrs']['className'] ) && strpos( $block['attrs']['className'], 'img-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 );
Adding PHP: https://docs.generatepress.com/article/adding-php/#code-snippets
-
waynewil
Hi Alvind,
That worked. Thank you for your excellent support. That has been evident since Day 1.
Wayne
-
Alvind
You’re welcome!
- You must be logged in to reply to this topic.