Site logo

[Resolved] Click the article link on page A to jump and then go to the new page B. How to s

Home Forums Support [Resolved] Click the article link on page A to jump and then go to the new page B. How to s

Home Forums Support Click the article link on page A to jump and then go to the new page B. How to s

Viewing 15 posts - 1 through 15 (of 23 total)
  • Author
    Posts
  • #2471492
    RYAN

    Click the article link on page A to jump and then go to the new page B. How do I set it?

    I want articles on the home page and articles on custom pages to jump like this

    #2471854
    Leo
    Staff
    Customer Support

    Hi there,

    Click the article link on page A to jump and then go to the new page B.

    Sorry but I don’t understand what you are trying to achieve here – do you happen to have an example to show?

    #2472022
    RYAN

    For example, the following

    #2473269
    RYAN

    Anyone here?

    #2473286
    Fernando
    Customer Support

    Hi Ryan,

    Sorry, your previous response may have slipped through our system.

    To clarify, are you referring to a link opening in a new tab?

    #2473287
    RYAN

    yes
    I find Fernando knows me best
    I like you very much hahaha

    #2473327
    Fernando
    Customer Support

    You’re using the default template for the Blog page. For other archive pages, you seem to be using a Block Element – Content Template.

    It would be easier, and less code would be needed if both the Blog and Archive pages are built in the same way. Would you be open to using the same Content Template you have in your Blog as well?

    #2473346
    RYAN

    Yes. Then how can I set it

    #2473356
    Fernando
    Customer Support

    Add cu-new-tab to the class list of the Headline or Image Block link.

    Adding Custom Classes: 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'], 'cu-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;
    }
     
    add_filter( 'render_block', 'db_rerender_url_new_tab', 10, 2 );

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

    #2473375
    RYAN

    Other pages are OK,

    The home page is still not good. What else should be set for this page

    #2473378
    Fernando
    Customer Support

    I see. If it’s a menu item, you need to set it in the Menu itself. It’s shown here: https://docs.generatepress.com/article/using-the-wordpress-menu-builder/#opening-in-a-new-window-tab

    Enable “Open in new tab/window” for the menu items as shown in the link above.

    #2473384
    RYAN

    I added it, but it still doesn’t work. Clicking the article link will not open a new tab page

    #2473388
    Fernando
    Customer Support

    The cu-new-tab is for GB Blocks in your Content Template.

    For menu items, you need to follow what I said here: https://generatepress.com/forums/topic/click-the-article-link-on-page-a-to-jump-and-then-go-to-the-new-page-b-how-to-s/#post-2473378

    There should be a toggle there to set a menu item to Open in a new tab.

    #2473410
    RYAN

    Yes, I checked it, but it is not the page to jump to by clicking the article link, but the function to jump to a new page when clicking the home page. You can check my icon or the home page of my website

    #2473430
    Fernando
    Customer Support

    Can you reiterate what you want to happen? I’m not sure I’m still understanding what you want to happen. 🙂

    If you can provide an example, that would be great.

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