- This topic has 11 replies, 4 voices, and was last updated 1 year, 6 months ago by
David.
-
AuthorPosts
-
August 18, 2019 at 6:03 pm #987531
Chelsea
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 #987561Leo
StaffCustomer 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.Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/August 19, 2019 at 2:37 pm #988336Chelsea
Aloha 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 #988390Tom
Lead DeveloperLead DeveloperHi there,
I’m not seeing the code in your source. Can you try clearing your caching plugin?
Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/
Ongoing Development: https://generatepress.com/ongoing-developmentAugust 19, 2019 at 5:43 pm #988403Chelsea
Aloha 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 #989010Tom
Lead DeveloperLead DeveloperWhere can I see a link to post 599?
Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/
Ongoing Development: https://generatepress.com/ongoing-developmentAugust 21, 2019 at 12:33 am #989418Chelsea
Hi 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 #989566David
StaffCustomer 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
Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/August 22, 2019 at 4:59 pm #991134Chelsea
Aloha 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 #991348David
StaffCustomer SupportYou should be able to do this instead:
jQuery(document).ready(function($) { $('.post-599 a').attr('target', '_blank'); });
Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/August 23, 2019 at 4:00 pm #991922Chelsea
Perfect!
Thank you so much! You guys are da best!
Aloha!
August 24, 2019 at 3:39 am #992125David
StaffCustomer SupportGlad we could be of help
Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/ -
AuthorPosts
- You must be logged in to reply to this topic.