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.

Link Post format – open in new tab

  • 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

  • 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

  • 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}}

  • 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.

  • Thanks, I’ll pass this feedback along to the dev team so we can look into improving it. 🙂

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