1:页面链接添加.html后缀
默认情况下WordPress不能添加.html后缀,直接添加的话会直接将.转换成-。
方法:将下面代码添加主题functions.php中即可。
// 页面链接添加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';
}
}
上述代码适合伪静态的固定链接形式使用,比如:
/%postname%.html
/%post_id%.html
同时需要在固定链接里面重新保存一下设置。
2.上传的图片自动改名
functions.php里面加上如下代码即可:
add_filter('wp_handle_upload_prefilter', 'custom_upload_filter' );
function custom_upload_filter( $file ){
$info = pathinfo($file['name']);
$ext = $info['extension'];
$filedate = date('YmdHis').rand(10,99);//为了避免时间重复,再加一段2位的随机数
$file['name'] = $filedate.'.'.$ext;
return $file;
}
3.文章的段落首行缩进
添加如下代码即可:
注意添加到functions.php中的<?php ?>里面。
//文章首行缩进
function Bing_text_indent($text){
$return = str_replace('<p>', '<p style="text-indent:2em;">',$text);
return $return;
}
add_filter('the_content','Bing_text_indent');
比起网上流传的代码,这个是我改过之后的,其实也简单也就是将<p改为<p>,即加了 一个>,如果不加的话显示会有问题。
4.图片弹出效果
即浮动窗口打开,如果文章里面有图片的话,图片是有时是会在新窗口中打开,有点影响体验,如果图片可以在浮动窗口中打开的话,体验会上一个台阶。
实现方法:
1:添加插件Easy FancyBox,可以在插件商店里面搜索安装。

后台的插件商店经常打不开,可以直接百度搜索后找到官方下载地址后,下载然后上传安装。
2:插件 Fancy Gallery
3:插件 FancyBox Gallery
4:插件 FancyBox for WordPress
几个插件都可以,最简单的就是第一个,所以放在第一个。
5.评论可见
functions.php里面加上如下代码:
function reply_to_read($atts, $content=null) {
extract(shortcode_atts(array("notice" => '<p class="reply-to-read">温馨提示: 此处内容需要<a href="#respond" title="评论本文">评论本文</a>后才能查看.</p>'), $atts));
$email = null;
$user_ID = (int) wp_get_current_user()->ID;
if ($user_ID > 0) {
$email = get_userdata($user_ID)->user_email;
//对博主直接显示内容
$admin_email = "im@magrco.com";
if ($email == $admin_email) {
return $content;
}
} else if (isset($_COOKIE['comment_author_email_' . COOKIEHASH])) {
$email = str_replace('%40', '@', $_COOKIE['comment_author_email_' . COOKIEHASH]);
} else {
return $notice;
}
if (empty($email)) {
return $notice;
}
global $wpdb;
$post_id = get_the_ID();
$query = "SELECT `comment_ID` FROM {$wpdb->comments} WHERE `comment_post_ID`={$post_id} and `comment_approved`='1' and `comment_author_email`='{$email}' LIMIT 1";
if ($wpdb->get_results($query)) {
return do_shortcode($content);
} else {
return $notice;
}
}
add_shortcode('reply', 'reply_to_read');
使用的时候采用下面的代码:
[reply notice="评论后查看"]评论可见的内容[/reply]