13071077710
您的当前位置: 首页 > wordpress > functions.php

functions.php

时间: 2016-6-2

————屏蔽WordPress默认小工具————

// 屏蔽WordPress默认小工具
add_action( 'widgets_init', 'my_unregister_widgets' ); 
 function my_unregister_widgets() { 
 unregister_widget( 'WP_Widget_Archives' ); 
 unregister_widget( 'WP_Widget_Calendar' ); 
 unregister_widget( 'WP_Widget_Categories' ); 
 unregister_widget( 'WP_Widget_Links' ); 
 unregister_widget( 'WP_Widget_Meta' ); 
 unregister_widget( 'WP_Widget_Pages' ); 
 unregister_widget( 'WP_Widget_Recent_Comments' ); 
 unregister_widget( 'WP_Widget_Recent_Posts' ); 
 unregister_widget( 'WP_Widget_RSS' ); 
 unregister_widget( 'WP_Widget_Search' ); 
 unregister_widget( 'WP_Widget_Tag_Cloud' ); 
 unregister_widget( 'WP_Nav_Menu_Widget' ); 
}

————自定义登陆页面风格————  链接:http://pan.baidu.com/s/1pKZ3UGV 密码:9ir2  ————

//自定义登录页面风格(图片轮换背景)
function uazoh_custom_login_page_imgbackground() {
echo ' <script type="text/javascript" src="/wp-includes/js/jquery/jquery.js?ver=1.11.1"></script>
 <script src="'.get_bloginfo('template_directory').'/js/jquery.backstretch.min.js"></script>
<script>
jQuery(function(){
var imgsrc = "'.get_bloginfo('template_directory').'/images/login_page_bg";
var listArr = [imgsrc+"/1.jpg",imgsrc+"/2.jpg",imgsrc+"/3.jpg",imgsrc+"/4.jpg"];
jQuery(\'.login\').backstretch(listArr, {fade: 1000,duration: 5000});});</script>';
}
add_action('login_head', 'uazoh_custom_login_page_imgbackground');
//自定义登录页面风格
function uazoh_custom_login_page() {
echo'<style type="text/css">
body { background: none; }
#login {width: 320px;margin: auto;background: #FFF;margin-top: 8%;padding: 20px;border-radius: 3px;box-shadow: 0px 1px 1px 0px rgba(0,0,0,0.2);}
.login form {margin-top: 0;margin-left: 0;padding:6px 24px 10px;-webkit-box-shadow:none;box-shadow:none;}
.login form .forgetmenot{float:none}
.login .button-primary{float:none;background-color: #494949;font-weight: bold;color: #fff;width: 100%;height: 40px;border-width: 0;border-color:none}
#login form p.submit{padding: 20px 0 0;}
.wp-core-ui .button-primary.focus, .wp-core-ui .button-primary.hover, .wp-core-ui .button-primary:focus, .wp-core-ui .button-primary:hover{background:#1F1F1F}
.wp-core-ui .button.button-large{height:40px;line-height:38px;font-size:16px;}
input{outline:none!important}
</style>';
}
add_action('login_head', 'uazoh_custom_login_page');

————给文章图片自动添加alt和title信息————

//给文章图片自动添加alt和title信息
add_filter('the_content', 'imagesalt');
function imagesalt($content) {
 global $post;
 $pattern ="/<a(.*?)href=('|\")(.*?).(bmp|gif|jpeg|jpg|png)('|\")(.*?)>/i";
 $replacement = '<a$1href=$2$3.$4$5 alt="'.$post->post_title.'" title="'.$post->post_title.'"$6>';
 $content = preg_replace($pattern, $replacement, $content);
 return $content;
}
function image_alt_tag($content){
 global $post;preg_match_all('/<img (.*?)\/>/', $content, $images);
 if(!is_null($images)) {foreach($images[1] as $index => $value)
 {
 $new_img = str_replace('<img', '<img alt="'.get_the_title().'"', $images[0][$index]);
 $content = str_replace($images[0][$index], $new_img, $content);}}
 return $content;
}
add_filter('the_content', 'image_alt_tag', 99999);

Copyright © 2013-2019 子歇    版权所有   网站地图