Our intranet website has a link which opens a Windows Explorer window from within the page. After a WordPress update, this functionality was lost. After some Googling I was able to find a solution by adding the following code to the functions.php file:
function allowed_link_protocols_filter($protocols)
{
$protocols[] = 'file';
return $protocols;
}
add_filter('kses_allowed_protocols', 'allowed_link_protocols_filter');
A few days ago, our WordPress website got another update after which I noticed that the added functionality was removed again (probably overwritten by the new functions.php file of the new version).
How can I add something to functions.php so that I don’t have to add it again with every new update that follows?
Please note that, though I know my way around PHP a little bit, I have no WordPress experience.
2
Answers
One way would be to create a child theme of your theme, which will not be overwritten when you update the theme.
But if you just want to add a single function, I would suggest creating a plugin.
With FTP go to the folder
wp-content
>>plugins
Inside the
plugins
folder create a new folder calledmy_protocol_filter
Inside of this new created folder, create a php file with the same name
my_protocol_filter.php
Inside of this php file you have to paste the following code
The comment defines the name of your plugin. Below that you paste your code
this is just an update, I found that the best way to put custom javascript is directly through the page it self, in every page there is an editor choose text from it and put your javascript there like below, it work like a charm without causing any conflict.