- This topic has 11 replies, 4 voices, and was last updated 4 years, 8 months ago by David.
-
AuthorPosts
-
August 18, 2019 at 6:03 pm #987531Chelsea
Aloha GP!
I’ve been reading through your forums and I haven’t found the specific answer to my question.
Can you please assist me with targeting a specific blog post to open in a new browser window. I do not want all of my post to open in new windows but need a specific post (in the blog post feed which I named “Info / Tips”) to open in a new browser tab. The reason is that it’s a post that contains a music link so people can listen to live Hawaiian radio while browsing the website… I need this post to open as a new tab so the music can continue to play while people browse the site on their original tab.
Thank you!
August 18, 2019 at 8:40 pm #987561LeoStaffCustomer SupportHi there,
Hmm not 100% sure if that’s possible but perhaps try the solution here:
https://generatepress.com/forums/topic/force-open-all-wordpress-blog-posts-in-new-tab-target_blank/#post-612849But instead of
$('h2.entry-title a').each(function() {
Try
$('.post-xxx h2.entry-title a').each(function() {
and replace
xxx
with the ID of the post.August 19, 2019 at 2:37 pm #988336ChelseaAloha Leo – thank you for instructions. I tried it but it did not make the post open in a new window. Here is what I did:
I added the code to wp_footer in the Appearance / Elements / Add Hook setting. I executed shortcodes and I executed PHP – Priority is set to 10. Display rules is Location: Entire site.
Here is the script I added:
<script type=”text/javascript”>
//<![CDATA[
jQuery(document).ready(function($) {
$(‘.post-599 h2.entry-title a’).each(function() {
var a = new RegExp(‘/’ + window.location.host + ‘/’);
if(!a.test(this.href)) {
$(this).click(function(event) {
event.preventDefault();
event.stopPropagation();
window.open(this.href, ‘_blank’);
});
}
});
});
//]]>
</script>August 19, 2019 at 5:22 pm #988390TomLead DeveloperLead DeveloperHi there,
I’m not seeing the code in your source. Can you try clearing your caching plugin?
August 19, 2019 at 5:43 pm #988403ChelseaAloha Tom,
Since it wasn’t working I removed the hook from Elements : )
I just added the hook back to Elements & also cleared my caching plugin.
You should be able to see it now.
Thank you!
August 20, 2019 at 8:35 am #989010TomLead DeveloperLead DeveloperWhere can I see a link to post 599?
August 21, 2019 at 12:33 am #989418ChelseaHi Tom,
The link to post 599 is on the https://mauioceanrentals.net/info-tips/ page which is houses the blog. Post 599 is the post named “Live Hawaiian Radio”. Is that what you are asking?
August 21, 2019 at 5:11 am #989566DavidStaffCustomer SupportHi there,
try this:
jQuery( document ).ready( function( $ ) { $( '.post-599 a' ).click( function( event ){ event.preventDefault(); window.open(( this ).href, 'window name', 'features'); }); });
The ‘window name’ and ‘features’ are two arguments of the .open() function – you can leave them as is, or look up the arguments to define specific settings. No need to check execute PHP in the hook
August 22, 2019 at 4:59 pm #991134ChelseaAloha David!
That worked! Thank you!
Quick question: I looked up the arguments of the .open()funtion but couldn’t find an adjustment for opening the post 599 in a new tab vs. new browser window. Curious what I would add to the code to make it open a new browser “tab” vs. an entire new window?
Thank you so much!
Aloha!August 23, 2019 at 2:10 am #991348DavidStaffCustomer SupportYou should be able to do this instead:
jQuery(document).ready(function($) { $('.post-599 a').attr('target', '_blank'); });
August 23, 2019 at 4:00 pm #991922ChelseaPerfect!
Thank you so much! You guys are da best!
Aloha!
August 24, 2019 at 3:39 am #992125DavidStaffCustomer SupportGlad we could be of help
-
AuthorPosts
- You must be logged in to reply to this topic.