Last active
December 23, 2020 20:21
-
-
Save elimn/5bac70de00ec92804dc7 to your computer and use it in GitHub Desktop.
MT | TEC | Change event, venue, or organizer links to the relevant website URL
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
* This changes the event link to the event website URL if that is set. | |
* NOTE: Comment out the add_filter() line to disable this function. | |
*/ | |
function tribe_set_link_website ( $link, $postId ) { | |
$website_url = tribe_get_event_website_url( $postId ); | |
// Only swaps link if set | |
if ( !empty( $website_url ) ) { | |
$link = $website_url; | |
} | |
return $link; | |
} | |
add_filter( 'tribe_get_event_link', 'tribe_set_link_website', 100, 2 ); | |
/* | |
* This changes the venue link to the venue website URL if that is set. | |
* NOTE: Uncomment the add_filter() line to enable this function. | |
*/ | |
function tribe_set_venue_website ( $link, $postId, $display, $venue_url ) { | |
$venue_link = tribe_get_venue_website_link( tribe_get_venue_id( $postId ) ); | |
// Only swaps link if set and full HTML <a> link is set | |
if ( !empty( $venue_link ) ) { | |
if ( $display ) { | |
$link = $venue_link; | |
} else { | |
$venue_url = tribe_get_event_meta( tribe_get_venue_id( $postId ), '_VenueURL', true ); | |
$parseUrl = parse_url( $venue_url ); | |
if ( empty( $parseUrl['scheme'] ) ) { | |
$venue_url = "http://$venue_url"; | |
} | |
$link = $venue_url; | |
} | |
} | |
return $link; | |
} | |
//add_filter( 'tribe_get_venue_link', 'tribe_set_venue_website', 100, 4 ); | |
/* | |
* This changes the organizer link to the organizer website URL if that is set. | |
* NOTE: Uncomment the add_filter() line to enable this function. As of PRO v3.9.1 not all organizer links are filterable. | |
*/ | |
function tribe_set_organizer_website ( $link, $postId, $echo, $url, $name ) { | |
$organizer_link = tribe_get_organizer_website_link( tribe_get_organizer_id( $postId ), false); | |
// Only swaps link if set | |
if ( !empty( $organizer_link ) ) { | |
$link = $organizer_link; | |
} | |
return $link; | |
} | |
//add_filter( 'tribe_get_organizer_link', 'tribe_set_organizer_website', 100, 5 ); |
Hi This does not work any more? I tried it on function.php
Hello,
There is a note on the website mentioning that this snippet was written to work with the legacy calendar views. It may require additional customization to apply on sites using the updated 5.x calendar views.
https://theeventscalendar.com/knowledgebase/k/make-links-to-an-event-go-straight-to-the-event-website-url/
I wonder what are the required customization to work with 5.x calendar views.
We need to open the links (external) in a new tab directly from the calendar view instead of navigating users to the single event view.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi! This is exaclty what I'm looking for. Could you please let me know where I should put this code?