Wordpress drops file prefix after update

71 views Asked by At

TL;DR - why does Wordpress remove file:// from file links?

Our intranet page has a section containing icons with links behind them. All of a sudden (our guess is after an update), one of the links stopped working. The link is as follows (1):

<a href="file://vmdata/meetings" target="_blank"><img src="/img/meetings.jpg" style="width:75px; height:75px;"/></a>

The expected behaviour (in Internet Explorer (2)) is that the file explorer opens, and points to the share \vmdata\meetings, which has always worked up until now.

When I hover over the icon image I see the following code however:

http://vmdata/meetings

and when I check the HTML by viewing the source of the page, I see that the file:// prefix is indeed gone:

<a href="//vmdata/meetings" target="_blank" rel="noopener noreferrer">

To work around this issue, I had a look at a page on which the original creator had added the same type of links. My idea was to create a similar page, copy the HTML code on the page and link the icon to said page. I added the page and HTML link but after viewing the page, the result is exactly the same: the file:// prefix is gone.

My guess is that something within Wordpress is rewriting/removing the file:// link. My question now is twofold: how do I stop this rewriting/removing behaviour, and/or how can I add a link to a fileshare as before?

PS: the creator of the website is no longer available, and the website is running yet unmanaged. Only content creators are left. We have no Wordpress knowledge in house, so we're basically just trying to keep the site up and running (in wait for a new site).

(1) I realise that pointing to a server share from an intranet site is a very ugly way to publish files. However, as stated before, we're in a situation of if it ain't broke don't fix it with this website, so we just want to go back to a working situation. Creating a page to link to (hosted) documents would be a lot better, but is for various reasons not feasible.

(2) please don't bother pointing out NOT to use Internet Explorer (anymore), we all know that but we are stuck with it because it is a requirement for one of the major tools we all use everyday. As long as that tool doesn't support other browsers, we're stuck with IE (unfortunately).

1

There are 1 answers

0
Joe On

I found another question regarding this issue: can't save network share path as a link in wordpress 3.1

Apparently the correct way to add an allowed protocol into WordPress is to modify the functions.php file and add the following code:

function allowed_link_protocols_filter($protocols)
{
   $protocols[] = 'file';
   return $protocols;
}
add_filter('kses_allowed_protocols', 'allowed_link_protocols_filter');

More information can be found in the following article: https://developer.wordpress.org/reference/hooks/kses_allowed_protocols/

Adding the code above solved the problem for me, so I hope this helps others to solve similar issues in the future.