-
mxvjen
Hello,
I’m trying to achieve something similar to this …
https://generatepress.com/forums/topic/link-post-format-open-in-new-window/
… but with a custom post type (called ‘job’), and opening in a new tab instead of a new window.
Thank you,
Mark -
Hi there,
A quick way would be using a button block, set the dynamic text tag to
{{post_permalink}}then you can toggle the Open link in a new tab option.Here’s a screenshot for your reference:
https://app.screencast.com/ppGLp82P2K5iV -
mxvjen
Hey, thanks for your help appreciate the fast reply.
That’s an option but I was hoping to set the post title to a < h3 >, and the button suggestion above only seems to work if the button element is < a >.
Is there another option I can try please?
Thank you,
Mark -
Alvind
Hi Mark,
You can use this snippet:
add_filter('generateblocks_dynamic_tag_output', function ($output, $options) { if (isset($options['open_in_new_tab'])) { $output = str_replace('<a href=', '<a target="_blank" href=', $output); } return $output; }, 10, 2);Then use this snippet for the post title dynamic tag: {{post_title link:post|open_in_new_tab}}
-
wdburgdorf
Thanks for the workaround code. It would be nice to have this as switches, like for other links: new tab, nofollow, and sponsored. After all, these are all links, how are these dynamic links different?
Anyway, your code is a nice example of how to manipulate the output. Could come in handy for other applications, too.
-
Alvind
Thanks, I’ll pass this feedback along to the dev team so we can look into improving it. 🙂
- You must be logged in to reply to this topic.