WordPress优化

WP默认总是会带很多版权相关的东西。但是咱普通用户看着又不爽。清理下吧顺便在加个说说面板

WP的自定义清理

我用的noto-simple主题

在主题目录新建一个functions-diy.php

​```php
<?php
//function.php中插入该代码,该文件重命名为functions-diy.php
//require get_template_directory() . ‘/functions-diy.php’;

//说说
add_action(‘init’, ‘my_custom_init’);
function my_custom_init() {
$labels = array( ‘name’ => ‘说说’, ‘singular_name’ => ‘singularname’, ‘add_new’ => ‘发表说说’, ‘add_new_item’ => ‘发表说说’, ‘edit_item’ => ‘编辑说说’, ‘new_item’ => ‘新说说’, ‘view_item’ => ‘查看说说’, ‘search_items’ => ‘搜索说说’, ‘not_found’ => ‘暂无说说’, ‘not_found_in_trash’ => ‘没有已遗弃的说说’, ‘parent_item_colon’ => ‘’, ‘menu_name’ => ‘说说’ );
$args = array( ‘labels’ => $labels, ‘public’ => true, ‘publicly_queryable’ => true, ‘show_ui’ => true, ‘show_in_menu’ => true, ‘query_var’ => true, ‘rewrite’ => true, ‘capability_type’ => ‘post’, ‘has_archive’ => true, ‘hierarchical’ => false, ‘menu_position’ => null, ‘supports’ => array(‘title’,’editor’,’author’) );
register_post_type(‘shuoshuo’,$args);
}

//自定义登录页面的LOGO提示为网站名称
add_filter(‘login_headertitle’, create_function(false,”return get_bloginfo(‘name’);”));

//自定义登录页面的LOGO链接为首页链接
add_filter(‘login_headerurl’, create_function(false,”return get_bloginfo(‘url’);”));

// //修改登陆logo链接
// function custom_loginlogo_url($url) {
// return ‘https://shawshang.cn‘;
// }
// add_filter( ‘login_headerurl’, ‘custom_loginlogo_url’ );

//WordPress 去除后台标题中的“—— WordPress”
add_filter(‘admin_title’, ‘wpdx_custom_admin_title’, 10, 2);
function wpdx_custom_admin_title($admin_title, $title){
return $title.’ ‹ ‘.get_bloginfo(‘name’);
}

//去掉仪表盘最下面的wordpress链接
function footerText () {
return ‘’;
}

//页脚版本信息
function change_footer_admin () {return ‘’;}
add_filter(‘admin_footer_text’, ‘change_footer_admin’, 9999);
function change_footer_version() {return ‘’;}
add_filter( ‘update_footer’, ‘change_footer_version’, 9999);

//自定义登录页面的LOGO图片
function my_custom_login_logo() {
echo ‘‘;
}
add_action(‘login_head’, ‘my_custom_login_logo’);

//顶部工具栏
function my_edit_toolbar($wp_toolbar) {
$wp_toolbar->remove_node(‘wp-logo’); // 去掉 WordPress LOGO
//$wp_toolbar->remove_node(‘site-name’); // 去掉网站名称
//$wp_toolbar->remove_node(‘updates’); // 去掉更新提醒
//$wp_toolbar->remove_node(‘comments’); // 去掉评论提醒
//$wp_toolbar->remove_node(‘new-content’); // 去掉新建文件
$wp_toolbar->remove_node(‘top-secondary’); // 用户信息
}
add_action(‘admin_bar_menu’, ‘my_edit_toolbar’, 999);

//左侧顶级菜单
/*
function remove_menus() {
global $menu;
$restricted = array(
__(‘Dashboard’), // 仪表盘
__(‘Posts’), // 文章
__(‘Media’), // 媒体
__(‘Links’), // 链接
__(‘Pages’), // 页面
__(‘Appearance’), // 外观
__(‘Tools’), // 工具
__(‘Users’), // 用户
__(‘Settings’), // 设置
__(‘Comments’), // 评论
__(‘Plugins’) // 插件
);
end ($menu);
while (prev($menu)){
$value = explode(‘ ‘,$menu[key($menu)][0]);
if(strpos($value[0], ‘<’) === FALSE) {
if(in_array($value[0] != NULL ? $value[0]:”” , $restricted)){
unset($menu[key($menu)]);
}
}else {
$value2 = explode(‘<’, $value[0]);
if(in_array($value2[0] != NULL ? $value2[0]:”” , $restricted)){
unset($menu[key($menu)]);
}
}
}
}
// 是后台的情况时
if (is_admin()){
add_action(‘admin_menu’, ‘remove_menus’);
}
*/

//左侧子菜单
/*
具体的缩略名如何获取呢?这里举例说明:
我们点击仪表盘时 url 为 /wp-admin/index.php,点击首页时也是,点击更新时为 /wp-admin/update-core.php,其他的依次类推~
只需要获取顶级菜单和子菜单相应的缩略名,然后在 remove_submenu() 函数内添加 remove_submenu_page() 函数即可
/
/

function remove_submenu() {
// 删除仪表盘下的首页
remove_submenu_page(‘index.php’, ‘index.php’);
// 删除仪表盘下的更新
remove_submenu_page(‘index.php’, ‘update-core.php’);
}
if (is_admin()){
//删除子菜单
add_action(‘admin_init’,’remove_submenu’);
}
*/

//仪表盘无用模块
function example_remove_dashboard_widgets() {
global $wp_meta_boxes;
// 以下这一行代码将删除 “快速发布” 模块
unset($wp_meta_boxes[‘dashboard’][‘side’][‘core’][‘dashboard_quick_press’]);
// 以下这一行代码将删除 “引入链接” 模块
unset($wp_meta_boxes[‘dashboard’][‘normal’][‘core’][‘dashboard_incoming_links’]);
// 以下这一行代码将删除 “插件” 模块
unset($wp_meta_boxes[‘dashboard’][‘normal’][‘core’][‘dashboard_plugins’]);
// 以下这一行代码将删除 “近期评论” 模块
unset($wp_meta_boxes[‘dashboard’][‘normal’][‘core’][‘dashboard_recent_comments’]);
// 以下这一行代码将删除 “近期草稿” 模块
unset($wp_meta_boxes[‘dashboard’][‘side’][‘core’][‘dashboard_recent_drafts’]);
// 以下这一行代码将删除 “WordPress 开发日志” 模块
unset($wp_meta_boxes[‘dashboard’][‘side’][‘core’][‘dashboard_primary’]);
// 以下这一行代码将删除 “其它 WordPress 新闻” 模块
unset($wp_meta_boxes[‘dashboard’][‘side’][‘core’][‘dashboard_secondary’]);
// 以下这一行代码将删除 “概况” 模块
//unset($wp_meta_boxes[‘dashboard’][‘normal’][‘core’][‘dashboard_right_now’]);
}
add_action(‘wp_dashboard_setup’, ‘example_remove_dashboard_widgets’ );

//显示选项和帮助选项卡
function remove_screen_options(){ return false;}
add_filter(‘screen_options_show_screen’, ‘remove_screen_options’);
add_filter( ‘contextual_help’, ‘syz_remove_help’, 999, 3 );
function syz_remove_help($old_help, $screen_id, $screen){
$screen->remove_help_tabs();
return $old_help;
}

1
2
3
4
5

添加以下到`/wp-content/themes/noto-simple/functions.php`

```php
require get_template_directory() . '/functions-diy.php';

修改/wp-content/themes/noto-simple/footer.php

使用echo来自定义页脚

1
echo "<a href='http://beian.miit.gov.cn' title=''>蜀ICP备18033672号-1</a>";

登陆界面的图标

login.png放到/wp-content/themes/

把image.peg放到网站的根目录下

说说,新建shuoshuo.php到/wp-content/themes/noto-simple/footer.php下,在wp后台新建页面选择该模板保存即可

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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
<?php /*
Template Name: 说说
*/
get_header(); ?>
<style type="text/css">
#shuoshuo_content {
background-color: #fff;
padding: 10px;
min-height: 500px;
}

/* shuo */
body.theme-dark .cbp_tmtimeline::before {
background: RGBA(255, 255, 255, 0.06);
}

ul.cbp_tmtimeline {
padding: 0;
}

div class.cdp_tmlabel>li .cbp_tmlabel {
margin-bottom: 0;
}

.cbp_tmtimeline {
margin: 30px 0 0 0;
padding: 0;
list-style: none;
position: relative;
}

/* The line */
.cbp_tmtimeline:before {
content: '';
position: absolute;
top: 0;
bottom: 0;
width: 4px;
background: RGBA(0, 0, 0, 0.02);
left: 80px;
margin-left: 10px;
}

/* The date/time */
.cbp_tmtimeline>li .cbp_tmtime {
display: block;
/* width: 29%; */
/* padding-right: 110px; */
max-width: 70px;
position: absolute;
}

.cbp_tmtimeline>li .cbp_tmtime span {
display: block;
text-align: right;
}

.cbp_tmtimeline>li .cbp_tmtime span:first-child {
font-size: 0.9em;
color: #bdd0db;
}

.cbp_tmtimeline>li .cbp_tmtime span:last-child {
font-size: 1.2em;
color: #9BCD9B;
}

.cbp_tmtimeline>li:nth-child(odd) .cbp_tmtime span:last-child {
color: RGBA(255, 125, 73, 0.75);
}

div.cbp_tmlabel>p {
margin-bottom: 0;
}

/* Right content */
.cbp_tmtimeline>li .cbp_tmlabel {
margin: 0 0 45px 65px;
background: #9BCD9B;
color: #fff;
padding: .8em 1.2em .4em 1.2em;
/* font-size: 1.2em; */
font-weight: 300;
line-height: 1.4;
position: relative;
border-radius: 5px;
transition: all 0.3s ease 0s;
box-shadow: 0 1px 2px rgba(0, 0, 0, 0.15);
cursor: pointer;
display: block;
}

.cbp_tmlabel:hover {
/* transform:scale(1.05); */
transform: translateY(-3px);
z-index: 1;
-webkit-box-shadow: 0 15px 32px rgba(0, 0, 0, 0.15) !important
}

.cbp_tmtimeline>li:nth-child(odd) .cbp_tmlabel {
background: RGBA(255, 125, 73, 0.75);
}

/* The triangle */
.cbp_tmtimeline>li .cbp_tmlabel:after {
right: 100%;
border: solid transparent;
content: " ";
height: 0;
width: 0;
position: absolute;
pointer-events: none;
border-right-color: #9BCD9B;
border-width: 10px;
top: 4px;
}

.cbp_tmtimeline>li:nth-child(odd) .cbp_tmlabel:after {
border-right-color: RGBA(255, 125, 73, 0.75);
}

p.shuoshuo_time {
margin-top: 10px;
border-top: 1px dashed #fff;
padding-top: 5px;
}

/* Media */
@media screen and (max-width: 65.375em) {
.cbp_tmtimeline>li .cbp_tmtime span:last-child {
font-size: 1.2em;
}
}

.shuoshuo_author_img img {
border: 1px solid #ddd;
padding: 2px;
float: left;
border-radius: 64px;
transition: all 1.0s;
}

.avatar {
-webkit-border-radius: 100% !important;
-moz-border-radius: 100% !important;
box-shadow: inset 0 -1px 0 #3333sf;
-webkit-box-shadow: inset 0 -1px 0 #3333sf;
-webkit-transition: 0.4s;
-webkit-transition: -webkit-transform 0.4s ease-out;
transition: transform 0.4s ease-out;
-moz-transition: -moz-transform 0.4s ease-out;
}

.zhuan {
transform: rotateZ(720deg);
-webkit-transform: rotateZ(720deg);
-moz-transform: rotateZ(720deg);
}

/* end */
</style>
</head>

<body>
<div id="primary" class="content-area" style="">
<main id="main" class="site-main" role="main">
<div id="shuoshuo_content">
<ul class="cbp_tmtimeline">
<?php query_posts("post_type=shuoshuo&post_status=publish&posts_per_page=-1");
if (have_posts()) : while (have_posts()) : the_post(); ?>
<li> <span class="shuoshuo_author_img"><img src="/image.jpg" class="avatar avatar-48" width="48" height="48"></span>
<a class="cbp_tmlabel" href="javascript:void(0)">
<p></p>
<p><?php the_content(); ?></p>
<p></p>
<p class="shuoshuo_time"><i class="fa fa-clock-o"></i>
<?php the_time('YnjG:i'); ?>
</p>
</a>
<?php endwhile;
endif; ?>
</li>
</ul>
</div>
</main>
<!-- .site-main -->
</div>
<script type="text/javascript">
$(function() {
var oldClass = "";
var Obj = "";
$(".cbp_tmtimeline li").hover(function() {
Obj = $(this).children(".shuoshuo_author_img");
Obj = Obj.children("img");
oldClass = Obj.attr("class");
var newClass = oldClass + " zhuan";
Obj.attr("class", newClass);
}, function() {
Obj.attr("class", oldClass);
})
})
</script>
<?php //get_sidebar();
?>
<?php get_footer(); ?>

说说页面的头像

默认是读取的网站根目录下的image.jpg

网页的图标,在主题-自定义里面更换

登陆的小部件在/wp-includes/widgets/class-wp-widget-meta.php里面,去掉不想要的部分即可

1
2
3
4
添加以下到主题目录下的`functions.php`

​```php
require get_template_directory() . '/functions-diy.php';

修改footer.php

使用echo来自定义页脚

1
2
echo "Theme:Noto Simple<br>";
echo "<a href='http://beian.miit.gov.cn' title=''>蜀ICP备18033672号-1</a>";