Skip to content

Instantly share code, notes, and snippets.

@cliffordp
Last active April 6, 2023 13:11
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cliffordp/3584b8aee70cde484700 to your computer and use it in GitHub Desktop.
Save cliffordp/3584b8aee70cde484700 to your computer and use it in GitHub Desktop.
Open Event Website, Organizer, and Venue links in new window
<?php
/**
* The Events Calendar: Open event website, organizer, and venue links in new window.
*
* Filters are found in these files:
* /wp-content/plugins/the-events-calendar/src/functions/template-tags/link.php
* /wp-content/plugins/events-calendar-pro/src/functions/template-tags/general.php
* /wp-content/plugins/the-events-calendar/src/functions/template-tags/organizer.php
* /wp-content/plugins/the-events-calendar/src/functions/template-tags/venue.php
*
* @link https://gist.github.com/cliffordp/3584b8aee70cde484700
*
* @return string
*/
add_filter( 'tribe_get_event_website_link_target', 'cliff_blank_target_for_new_window' );
add_filter( 'tribe_get_organizer_website_link_target', 'cliff_blank_target_for_new_window' );
add_filter( 'tribe_get_venue_website_link_target', 'cliff_blank_target_for_new_window' );
function cliff_blank_target_for_new_window() {
return '_blank';
}
@ybalkind
Copy link

Hi CliffordP. Can you please explain how to use this code. To I just place it in the functions file?

Also why does it contain your name in the code "cliff_blank...."?

@searchn4
Copy link

Hi CliffordP, Can you explain why your name is in the code?

@cliffordp
Copy link
Author

Hi. I put my name in my snippets as a way to namespace them. If I were to name them generically like 'remove_link', it would be ripe for conflicts. Snippets are to be reviewed/customized.

Please reference https://theeventscalendar.com/knowledgebase/k/best-practices-for-implementing-custom-code-snippets/ for how/where to install them.

Just rename them yourself when you install them :)

@Goalfair
Copy link

This does not work for the organizer link (at least not as of right now). According to
/wp-content/plugins/the-events-calendar/src/functions/template-tags/organizer.php

it is 'tribe_get_event_organizer_link_target'
instead of 'tribe_get_organizer_website_link_target'

For those wondering where to put this code:
Put it in the functions.php of your theme. To avoid it being overwritten by theme updates create a child theme, see: https://developer.wordpress.org/themes/advanced-topics/child-themes/
There are also several wordpress plugins which allow you to add code simply via the wp dashboard.

@cliffordp
Copy link
Author

Thanks for sharing.
Those tips are part of that Knowledgebase article :)

@gavin310
Copy link

gavin310 commented Apr 6, 2023

Thanks, still works!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment