Is there a way to get hyperlinks that are written in event descriptions to display hot?
In the description fields of iCal events that I am importing into EO using the iCal URL feed, I have written links to different sites associated with the event (let’s say a description included a link to https://www.sxsw.com/, for example). When the iCal file is parsed and displayed in my event list, the text for the hyperlink stays, but the link is no longer hot.
I am guessing that the solution would be in the iCal parser PHP file, but wanted to check with you to see what that line of code would be to restore the hyperlink.
Much appreciated 🙂
Chad Green
Hi Chad,
Do you have a link to the feed you are importing?
Stephen Harris
Hi Chad,
That feed doesn’t contain any links, only URLs. You could make those URLs clickable with the code below, but as for any links with non-URL text, I’m afraid the links are just not in the feed.
/**
* Convert an URLs in $value to hyperlinks.
*/
function linkify($value)
{
$links = array();
// Extract existing links and tags
$value = preg_replace_callback('~(.*?|<.*?>)~i', function ($match) use (&$links) {
return '<' . array_push($links, $match[1]) . '>';
}, $value);
$value = preg_replace_callback(
'~(?:(https?)://([^\s<]+)|(www\.[^\s<]+?\.[^\s<]+))(?<![\.,:])~i',
function ($match) use (&$links) {
$protocol = $match[1] ? $match[1] : 'http';
$link = $match[2] ?: $match[3];
return '<' . array_push($links, "$protocol://$link") . '>';
},
$value
);
// Insert all link
return preg_replace_callback('/<(\d+)>/', function ($match) use (&$links) {
return $links[$match[1] - 1];
}, $value);
}
add_action( 'eventorganiser_ical_property_description', function($content, $modifiers, $ical_parser ){
$ical_parser->current_event['post_content'] = linkify( $content );
}, 10, 3 );
Stephen Harris
Thanks Stephen,
You know, this code will solve my problem. I had not described my problem correctly. I was looking to make URLs in the description clickable. My mistake, but you picked up on it!
Much appreciated.
Chad Green
Where should this code live? I tried inserting it into a couple of different “functions” files one at a time, but had not seen the results after I had refreshed the feed.
Chad Green
Preferably in your own custom plugin but your theme’s functions.php should do.
Stephen Harris
Hi Stephen,
when I put a hyperlink into my Google calendar it will not display anyway…but when I put it in the title it does…, that is how I use it to be shown in jetpack upcoming events…Now I did get ical synd to be able to get more than one google calendar to show it as one one the page. But the hyperlink in the title of the google events is not shown. You can see it here: http://www.babyzeichen.net/uber-mich/
Any idea what I could do? Can I use this code above? But I have no idea where to put it…
Thanks Astrid
Astrid Saragosa
Oh, events start in september on my calendar.
Astrid Saragosa
Hi Astrid,
The calendar doesn’t support HTML in the event title. However, the following snippet will strip the link from the title in the calendar (but not effect it anywhere else). Please note that the calendar is cached, so there may not be an immediate change. You can clear the cache by updating an event (manually syncing will probably also do that).
The following should go in a custom plugin but can go in your theme’s functions.php
add_filter( 'eventorganiser_fullcalendar_event', function($event, $event_id) {
$event['title'] = strip_tags( get_the_title( $event_id ) );
return $event;
}, 2 );
Stephen Harris
Great thanks!!! This worked easily and immediately! 🙂
Best Astrid
Astrid Saragosa