Last active
February 26, 2020 21:55
-
-
Save cliffordp/be034504a2c530495b7d58e704352069 to your computer and use it in GitHub Desktop.
The Events Calendar: Change Event Archives' iCalendar export links to webcal://
This file contains hidden or 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 | |
/** | |
* The Events Calendar: Change Event Archives' iCalendar export links to webcal:// | |
* | |
* This causes the "iCal Export" button to recommend to calendar applications | |
* (e.g. Apple, Outlook, etc.) that they should *subscribe* instead of *download*. | |
* | |
* We have to use JavaScript instead of PHP because the "Export Events" | |
* iCalendar link gets built via JS via | |
* /wp-content/plugins/the-events-calendar/src/resources/js/tribe-events.min.js | |
* (the script with the `tribe-events-calendar-script` handle). | |
* | |
* If we were to use PHP (using the `tribe_get_ical_link`, | |
* `tribe_get_single_ical_link`, and `tribe_events_force_filtered_ical_link` | |
* filters), the link would be static instead of being dynamic to things like | |
* an Event Category archive page. | |
* | |
* @link https://gist.github.com/cliffordp/be034504a2c530495b7d58e704352069 | |
* @link https://tribe.uservoice.com/forums/195723-feature-ideas/suggestions/31305556-add-true-subscribe-functionality-for-ical-google | |
*/ | |
add_action( 'wp_footer', 'cliff_ical_link_js_override_webcal', 100 ); | |
function cliff_ical_link_js_override_webcal() { | |
wp_enqueue_script( 'jquery' ); | |
?> | |
<script type="text/javascript"> | |
jQuery( document ).ready( function ( $ ) { | |
var url = $( 'a.tribe-events-ical' ).attr( 'href' ); | |
url = url.replace( 'https://', 'webcal://' ); | |
url = url.replace( 'http://', 'webcal://' ); | |
$( 'a.tribe-events-ical' ).attr( 'href', url ); | |
} ); | |
</script> | |
<?php | |
} |
Hey, I know you haven't been on here in a while, but I'm having trouble knowing exactly where this is supposed to go. The closest I've come is ical.php, but I don't see where in there makes the most sense. Can you help?
I haven't seen these comments before... this snippet (without opening PHP tag) goes in your child theme's functions.php
If you need more help, please contact https://support.theeventscalendar.com/
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Can you test the following link -> It seems to be working as a true subscribe link for me. If so, I think it would be great to share with others.
webcal://yoursite.org/calendar/list/?tribe_paged=0&tribe_event_display=list&ical=1&tribe_display=list
Please note that we use /calendar/ instead of /events/ after the domain.
Question -> do you have a snippet that can change the current URL to
webcal://yoursite.org/calendar/list/?tribe_paged=0&tribe_event_display=list&ical=1&tribe_display=list
Currently, I need to email people the link...