Event details page – open "Website:" in new window

Home Forums Calendar Products Events Calendar PRO Event details page – open "Website:" in new window

Viewing 15 posts - 1 through 15 (of 15 total)
  • Author
    Posts
  • #1079522
    Todd
    Participant

    I’d like to have the “Website:” links on the Event details page open in new windows. I tried the code on this page, but it did not work:
    https://gist.github.com/theeventscalendar/aacd642414ed838aecb7

    When I “Inspect” it’s easy to see the: target=”_self” , but I cannot find this code in the plugin files.

    • This topic was modified 8 years, 2 months ago by Todd.
    • This topic was modified 8 years, 2 months ago by Todd.
    • This topic was modified 8 years, 2 months ago by Todd.
    • This topic was modified 8 years, 2 months ago by Todd.
    #1080259
    Cliff
    Member

    Hi Todd. Thanks for including that link.

    I assume you obtained it from our KB article about this topic.

    I’ll flag our KB authors, but that snippet is outdated now. If you look in /wp-content/plugins/the-events-calendar/src/functions/template-tags/link.php, there’s now a filter specifically for this purpose: tribe_get_event_website_link_target

    Here’s a snippet to leverage it:

    Here: https://gist.github.com/cliffordp/3584b8aee70cde484700

    Please let me know how things go for you.

    #1084551
    Scott
    Participant

    On the link.php I was able to change

    apply_filters( 'tribe_get_event_website_link_target', '_self' ),

    to

    apply_filters( 'tribe_get_event_website_link_target', '_blank' ),

    and it worked perfectly. I tried the same thing with general.php but did not have the same effect for Organizer or Venue website links. How can we have those open in new windows as well?

    #1084671
    Todd
    Participant

    Cliff,

    That worked for the Details Website link. Thank you!

    I’d also like the Venue Website link to open in a new window. Is there a filter for that? Or, can you assist us in creating a filter?

    Example: http://www.coloradograndparent.com/event/rhino-meet-and-greet/2016-03-30/
    I’d like the denverzoo.org link to open in a new window.

    Thanks!

    #1086089
    Brook
    Participant

    Howdy Todd,

    Definitely we can help. It’s the exact same principle, only you are targeting the filter ‘tribe_get_venue_website_link_target’ instead. Set that _blank like you did with the event website and you’re golden.

    That what you needed?

    Cheers!

    – Brook

    #1086131
    Todd
    Participant

    Brook,

    Is there already the filter ‘tribe_get_venue_website_link_target’? I can’t find it in /wp-content/plugins/the-events-calendar/src/functions/template-tags/link.php. If so, where is it? If not, do I copy lines 293-308 in the link.php file and change the filter to ‘tribe_get_venue_website_link_target’?

    Thanks,

    Todd

    #1086132
    Todd
    Participant

    Brook,

    Ah ha. I took a second look and found the filter in /wp-content/plugins/the-events-calendar/src/functions/template-tags/venue.php.

    Line 414:
    apply_filters( ‘tribe_get_venue_website_link_target’, ‘_self’ ),
    Changed to:
    apply_filters( ‘tribe_get_venue_website_link_target’, ‘_blank’ ),

    Thanks!

    Todd

    #1087258
    Cliff
    Member

    Thanks for your patience during the time we were closed.

    Todd, you should NOT edit that venue.php file. If you do, your changes will be lost the next time you update the plugin.

    Instead, best practice for adding custom code (like to implement a PHP snippet to modify The Events Calendar) is to create a functionality plugin, unless it’s something specific to your theme, in which case best practice is to make sure you’re using a child theme, then add the customization to your child theme’s functions.php file.

    ===

    So, in your case, use the Gist code from my first reply as a template:

    • replace “tribe_get_event_website_link_target” with “tribe_get_venue_website_link_target”
    • replace “cliff_open_event_website_links_in_new_window” with something like “cliff_open_event_venue_links_in_new_window” — in both places

    So you can have both my Gist code snippet AND your new snippet (in your theme’s functions.php file, for example) so that both Event Website links and Venue Website links open in a new window.

    I hope this information helps!

    #1087321
    Todd
    Participant

    Thanks, Cliff.

    I see what you mean. I will add the filter to my child theme’s function.php file.

    Todd

    #1087327
    Cliff
    Member

    Thanks. Let us know if you need anything else.

    #1087821
    Scott
    Participant

    Hi Cliff, I am still lost. I have this at the bottom of my functions.php file:

    /*
    * The Events Calendar Open gCal Links in New Windows
    * @version 3.10
    */
    add_action( 'tribe_events_single_event_after_the_meta', 'tribe_open_gcal_new_tab' );
    function tribe_open_gcal_new_tab() { 
    echo '<script>
    /* Open gCal Links in New Windows */
    	jQuery("a.tribe-events-gcal")
    	.addClass("external")
    			.click( function() {
    				window.open(this.href);
    				return false;
    			});
    </script>';	
     }
     
     <?php
    /**
      * From https://gist.github.com/cliffordp/3584b8aee70cde484700
      * 
      * Open Event Website links in new window (not Organizer or Venue website links)
      * Filter is found in
      * /wp-content/plugins/the-events-calendar/src/functions/template-tags/link.php
      * and
      * /wp-content/plugins/events-calendar-pro/src/functions/template-tags/general.php
      */
    add_filter( 'tribe_get_venue_website_link_target', 'cliff_open_event_venue_links_in_new_window' );
    function cliff_open_event_venue_links_in_new_window() {
    	return '_blank';
    }

    And yet the only link that opens in a new window is the Details website. What am I missing?

    Thank you,

    Scott

    For some reason when I posted this it changed the code but I have copied and made the changes as per this discussion. Example page: https://www.coconutgrovechamber.com/event/starlight-movie-classics-sunday-march-6/

    #1087997
    Cliff
    Member

    Hi Scott. Yes, your code snippet got mangled by our forum…

    Anyway, I think this is what you’re actually wanting:

    Here: https://gist.github.com/cliffordp/3584b8aee70cde484700

    Let me know.

    #1091343
    Scott
    Participant

    Unfortunately that breaks the site, not all the pages, but most. When I try and go to the events page it show nothing but a blank page. Weird. I can live with it but maybe this is an option you could build into the next version where you have the option to open the link in a new window. If you have time to think of another way to do it, great! But if it’s something to do with my theme, I understand.

    Scott

    #1091626
    Cliff
    Member

    Sorry that happened. I tested it on my local site and it worked just fine so there could be some conflicts going on.

    Please follow our Testing for Conflicts Guide and see if that helps narrow down the cause of this. Hopefully it’ll work with a WordPress default theme like Twenty Fifteen and all other plugins inactive.

    As far as an option, I’m pretty sure we won’t be adding that since there’s already a way to do it via hooks — just from my experience with how the development team evaluates such requests. If you really feel strongly about having it as a GUI setting, you can submit it to our UserVoice page.

    If you post it, feel free to link to it from here in case anyone comes across this forum thread in the future.

    Thanks.

    #1097971
    Support Droid
    Keymaster

    This topic has not been active for quite some time and will now be closed.

    If you still need assistance please simply open a new topic (linking to this one if necessary)
    and one of the team will be only too happy to help.

Viewing 15 posts - 1 through 15 (of 15 total)
  • The topic ‘Event details page – open "Website:" in new window’ is closed to new replies.