Archived topic
Click the article link on page A to jump and then go to the new page B. How to s
22 replies · Started by RYAN on December 23, 2022
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
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?
For example, the following
Anyone here?
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?
yes
I find Fernando knows me best
I like you very much hahaha
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?
Yes. Then how can I set it
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
Other pages are OK,
The home page is still not good. What else should be set for this page
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.
I added it, but it still doesn't work. Clicking the article link will not open a new tab page
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.
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
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.
