1- 所有外链在新标签打开 / Open all external links in new tab
function rt_add_link_target( $content ){
// use the <a> tag to split into segments
$bits = explode( '<a ', $content );
// loop though the segments
foreach( $bits as $key=>$bit ){
// fix the target="_blank" bug after the link
if ( strpos( $bit, 'href' ) === false ) continue;
// find the end of each link
$pos = strpos( $bit, '>' );
// check if there is an end (only fails with malformed markup)
if( $pos !== false ){
// get a string with just the link's attibutes
$part = substr( $bit, 0, $pos );
// for comparison, get the current site/network url
$siteurl = network_site_url();
// if the site url is in the attributes, assume it's in the href and skip, also if a target is present
if( strpos( $part, $siteurl ) === false && strpos( $part, 'target=' ) === false ){
// add the target attribute
$bits[$key] = 'target="_blank" ' . $bits[$key];
}
}
}
// re-assemble the content, and return it
return implode( '<a ', $bits );
}
2- 启用全站 CDN 后获取访客的真是 IP,尤其是针对评论 IP 显示为 CDN 节点 IP 时使用 / Get the real IP of visitor under the entire site load from a CDN, especially when the IP of comments show as the IP of a CDN server.
在 WordPress 主题配置文件 wp-config.php
中加入 / Add this piece of code to WordPress's configuration file wp-config.php
:
if (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) {
$list = explode(',', $_SERVER['HTTP_X_FORWARDED_FOR']);
$_SERVER['REMOTE_ADDR'] = $list[0];
}
Still updating...
Comments | NOTHING