Excellent software and practical tutorials
Solution to the problem that Xunlei hyperlink cannot be used in WordPress
Thunder Hyperlink thunderThe protocol cannot be used in WordPress, except for http: and https:. When you enter thunder:, it will be automatically filtered out by the system. There are some resources on the Internet.ThunderIn the form of a hyperlink, sometimes the Thunder protocol must be used. How to enable Thunder in WP?magnet,ed2kWhat about other protocols? Let's analyze how to enable support for these protocols.
Add new protocols such as Thunder, Magnet, and Ed2k to WordPress hyperlinks
To prevent SQL injection, XSS and other attacks, WordPress will automatically filter the content when saving the article, resulting in the automatic deletion of unsupported protocol headers in hyperlinks (for example: thunder://, magnet:?xt=urn:btih:).
The simplest and most brutal solution is to turn off the filtering function.
Modify the wp-includes/post.php file and change $postarr = sanitize_post($postarr, 'db');
Comment out.
//$postarr = sanitize_post($postarr, 'db');
This method is simple and practical, but it means giving up the prevention function of WordPress and creating security risks, so it is not recommended.
How to effectively support new protocols such as thunder, magnet, ed2k, etc.
Method 1: Modify wp-includes/functions.php to add new protocol support
Modify wp-includes/functions.php function wp_allowed_protocols()
if ( empty( $protocols ) ) { $protocols = array( 'http', 'https', 'ftp', 'ftps', 'mailto', 'news', 'irc', 'gopher', 'nntp', 'feed', 'telnet', 'mms', 'rtsp', 'sms', 'svn', 'tel', 'fax', 'xmpp', 'webcal', 'urn' ); }
Directly add the new protocol that needs to be added, for example:
if ( empty( $protocols ) ) { $protocols = array( 'http', 'https', 'ftp', 'ftps', 'mailto', 'news', 'irc', 'gopher', 'nntp', 'feed', 'telnet', 'mms', 'rtsp', 'sms', 'svn', 'tel', 'fax', 'xmpp', 'webcal', 'urn' , 'thunder' , 'magnet' ,'ed2k'); }
There is a problem with this method: since the global variable wp-includes/functions.php file is modified, each new version upgrade of WordPress will overwrite the functions.php file, and this file must be manually modified again. If your WP version is not updated very frequently, you can use this method.
Method 2: Modify functions.php in the theme to add support for the new protocol
Modify wp-content/themes/theme name/functions.php and add the following content:
function ss_allow_thunder_protocol( $protocols ){ $protocols[] = 'thunder'; return $protocols; } function ss_allow_magnet_protocol( $protocols ){ $protocols[] = 'magnet'; return $protocols; } function ss_allow_ed2k_protocol( $protocols ){ $protocols[] = 'ed2k'; return $protocols; } add_filter( 'kses_allowed_protocols' , 'ss_allow_thunder_protocol' ); add_filter( 'kses_allowed_protocols' , 'ss_allow_magnet_protocol' ); add_filter( 'kses_allowed_protocols' , 'ss_allow_ed2k_protocol' );
Paste the content at the bottom of the functions.php file. If you want to add other protocols, just modify it according to the above code.
Or if you install a plug-in with code insertion function, just add the above code to the plug-in.
Recommended code management plugin:Powerful and flexible code management plug-in WPCode can insert any JS, CSS, PHP code conditionally