分享自己在用的wordpress中的function代码

WordPress有很多插件可以实现各种各样的功能,但我还是不太喜欢安装N多的插件,如果能用function代码解决的,我一般找这类代码,今天分享下自己在用的一些function代码。

分享自己在用的wordpress中的一些function代码

// 页面链接添加html后缀
add_action('init', 'html_page_permalink', -1);
function html_page_permalink() {
global $wp_rewrite;
if ( !strpos($wp_rewrite->get_page_permastruct(), '.html')){
$wp_rewrite->page_structure = $wp_rewrite->page_structure . '.html';
}
}

// 排除页面文件,为分类目录的地址后面添加/
function nice_trailingslashit($string, $type_of_url) {
if ( $type_of_url != 'single' && $type_of_url != 'page' )
$string = trailingslashit($string);
return $string;
}
add_filter('user_trailingslashit', 'nice_trailingslashit', 10, 2);

//修改登录界面,添加bing大图背景
function custom_login_head(){
$str=file_get_contents('http://cn.bing.com/HPImageArchive.aspx?idx=0&n=1');
if(preg_match("/<url>(.+?)<\/url>/ies",$str,$matches)){
$imgurl='http://cn.bing.com'.$matches[1];
echo'<style type="text/css">body{background: url('.$imgurl.');width:100%;height:100%;background-image:url('.$imgurl.');-moz-background-size: 100% 100%;-o-background-size: 100% 100%;-webkit-background-size: 100% 100%;background-size: 100% 100%;-moz-border-image: url('.$imgurl.') 0;background-repeat:no-repeat\9;background-image:none\9;}</style>';
}}
add_action('login_head', 'custom_login_head');

//修改登录界面的logo
function my_custom_login_logo() {
echo '<style type="text/css">
.login h1 a {
background-image:url("https://libinhao.cn/wp-content/uploads/2019/04/lbh.jpg") !important;
height: 87px; //修改为图片的高度
width: 87px; //修改为图标的宽度
-webkit-background-size: 84px; //修改为图标的宽度
background-size: 84px; //修改为图标的宽度
}
</style>';
}
add_action('login_head', 'my_custom_login_logo');
add_filter('login_headerurl', create_function(false,"return get_bloginfo('url');"));

//文章中链接在新页面打开
function autoblank($text) {
$return = str_replace('<a', '<a target="_blank"', $text);
return $return;
}
add_filter('the_content', 'autoblank');

//恢复链接菜单
add_filter( 'pre_option_link_manager_enabled', '__return_true');

作者:李彬豪博客
链接:https://libinhao.cn/273.html
文章版权归作者所有,欢迎保留原文链接转载。
THE END
分享
二维码
打赏
< <上一篇
下一篇>>
文章目录
关闭
目 录