wordpress自定义登录界面背景,logo,超链接以及title
wordpress自定义登录界面背景,logo,超链接以及title:
wordpress默认登录界面的logo,title,以及链接都是默认自带的,仔细查看 wp-login.php 这个文件在 83 行开始(我的wordpress版本为 3.6.1,不同版本有可能不同),可以看见如下代码:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
do_action( 'login_enqueue_scripts' ); do_action( 'login_head' ); if ( is_multisite() ) { $login_header_url = network_home_url(); $login_header_title = $current_site->site_name; } else { $login_header_url = __( 'http://wordpress.org/' ); $login_header_title = __( 'Powered by WordPress' ); } //这里添加了一个名为 login_headerurl 的过滤器,参数为字符串类型 $login_header_url = apply_filters( 'login_headerurl', $login_header_url ); //这里添加了一个名为 login_headertitle 的过滤器,参数为字符串类型 $login_header_title = apply_filters( 'login_headertitle', $login_header_title ); |
打开你的主题文件的 functions.php 文件,输入以下代码:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
/** * custom login header URL * @since 0.1 */ //此处使用 add_action 也是相同的效果 add_filter('login_headerurl','lmtf_custom_login_headerurl'); function lmtf_custom_login_headerurl($login_header_url){ $login_header_url = 'http://www.lastme.com'; //此处为链接地址 return $login_header_url; } /** * custom login header title * @since 0.1 */ //此处使用 add_action 也是相同的效果 add_filter('login_headertitle','lmtf_custom_login_headertitle'); function lmtf_custom_login_headertitle($login_header_title){ $login_header_title = 'User Login !'; return $login_header_title; } |
这时候打开登录界面将鼠标放到logo上,可以看见链接地址以及title都已经更换了.接下来修改登录界面的背景以及logo,还是在functions.php里面添加如下代码:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
/** * custom background color and logo * @since 0.1 */ //此处添加到 login_head 和 login_enqueue_scripts 钩子的效果是一样的 add_action('login_enqueue_scripts','lmtf_custom_login_form_wrapper'); function lmtf_custom_login_form_wrapper(){?> body.login{ //背景图片地址 background:#FFF url() no-repeat; } .login #login h1 a{ //logo图片地址 background-image:url(); background-size:300px auto; min-height:100px; } .login form{ margin-left:8px; padding:26px 24px 46px; font-weight:normal; background:#0F0F0F; border:1px solid #e5e5e5; -webkit-box-shadow:rgba(200,200,200,0.7) 0 4px 10px -1px; box-shadow:rgba(200,200,200,0.7) 0 4px 10px -1px; background:url(); } } |
可以看看我最终修改的登录界面的效果:
No Comments