Archived topic
How to make the article open on a new window?
1 reply · Started by Paul on July 1, 2022
hello how are you
1. when clicking the single post from sidebar https://prnt.sc/gdkdrqrmVtT8
2. when clicking the single post from the end of each article https://prnt.sc/-26uzvqlWFAg
3. when clicking the single post from the category https://prnt.sc/8QAqBiEShzFf
any one from the 3 different postion, i want to the article open on a new window,, how to do the setttings in generatepress theme or customising ?
pls guide and explain it here
1. The WordPress Latest Posts Block has no functionality to open posts in a new tab. You can try replacing it with a Query Loop Block and try the steps in number 2:
2. You can do the by filtering the Headline Block.
- Add my-url-title to the Headline Block: https://share.getcloudapp.com/6quzEBrv
- Add this PHP snippet:
function db_rerender_url( $block_content, $block ) {
if(!is_admin()){
if ( ! empty( $block['attrs']['className'] ) && 'my-url-title' === $block['attrs']['className'] ) {
$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', 10, 2 );
Adding PHP reference: https://docs.generatepress.com/article/adding-php/#code-snippets
3. You can do this through this PHP snippet in this article: https://docs.generatepress.com/article/generate_get_the_title_parameters/
Hope this helps!