Last active
October 24, 2023 11:45
-
-
Save Christian-Roth/aecac08adbd4ada6474f929552537d89 to your computer and use it in GitHub Desktop.
The Events Calendar – Show ics export link on single events
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 | |
/* Classic Editor: Activate ics links */ | |
add_filter( 'tec_views_v2_subscribe_link_ics_visibility', '__return_true', 20 ); | |
/* Classic Editor: Make ics link first item in dropdown */ | |
add_filter( 'tec_views_v2_subscribe_links', function ($links) { | |
if (isset($links['ics']) && is_singular( 'tribe_events' )) { | |
$links = array_merge(['ics' => $links['ics']], $links); | |
} | |
return $links; | |
} ); | |
/* Block Editor: Activate ics links */ | |
function custom_add_ical_link($output) { | |
if (function_exists('tribe_get_single_ical_link')) { | |
$ul_class = 'tribe-events-c-subscribe-dropdown__list'; | |
$li_class = 'tribe-events-c-subscribe-dropdown__list-item'; | |
$a_class = 'tribe-events-c-subscribe-dropdown__list-item-link'; | |
if (strpos($output, '<ul class="' . $ul_class . '">') ) { | |
$split_output = explode('<ul class="' . $ul_class . '">', $output); | |
$output = $split_output[0]; | |
$output .= '<ul class="' . $ul_class . '"><li class="' . $li_class . '"><a href="' . tribe_get_single_ical_link() . '" class="' . $a_class . '" target="_blank" rel="noopener noreferrer nofollow noindex">' . __('Export .ics') . '</a></li>'; | |
$output .= $split_output[1]; | |
} | |
} | |
return $output; | |
} | |
add_filter( 'tribe_template_html:events/blocks/parts/subscribe-list', 'custom_add_ical_link' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment