做个记录免得以后换主题又得重新弄…
评论链接跳转,防止权重流失,防黑帽
//评论者链接跳转_Start add_filter('get_comment_author_link', 'add_redirect_comment_link', 5); #如果需要评论内容内链接也跳转可加上下面这句 #add_filter('comment_text', 'add_redirect_comment_link', 99); function add_redirect_comment_link($text = ''){ $text=str_replace('href="', 'href="'.get_option('home').'/?r=', $text); $text=str_replace("href='", "href='".get_option('home')."/?r=", $text); return $text; } add_action('init', 'redirect_comment_link'); function redirect_comment_link(){ $redirect = $_GET['r']; if($redirect){ if(strpos($_SERVER['HTTP_REFERER'],get_option('home')) !== false){ header("Location: $redirect"); exit; } else { header("Location: ".get_bloginfo('url').""); exit; } } } //评论者链接跳转_End
WordPress默认文章编辑器增强代码
add_filter( 'pre_option_link_manager_enabled', '__return_true' ); //增强编辑器开始 function add_editor_buttons($buttons) { $buttons[] = 'fontselect'; $buttons[] = 'fontsizeselect'; $buttons[] = 'cleanup'; $buttons[] = 'styleselect'; $buttons[] = 'hr'; $buttons[] = 'del'; $buttons[] = 'sub'; $buttons[] = 'sup'; $buttons[] = 'copy'; $buttons[] = 'paste'; $buttons[] = 'cut'; $buttons[] = 'undo'; $buttons[] = 'image'; $buttons[] = 'anchor'; $buttons[] = 'backcolor'; $buttons[] = 'wp_page'; $buttons[] = 'charmap'; return $buttons; } add_filter("mce_buttons_3", "add_editor_buttons"); //增强编辑器结束
图片灯箱自动添加标签属性
想添加灯箱效果的请参考文章添加图片灯箱效果【Lightbox2.51】
//灯箱效果自动添加标签属性 add_filter('the_content', 'ATheme_pirobox_gall_replace'); function ATheme_pirobox_gall_replace ($content) { global $post; $pattern = "/<a(.*?)href=('|\")([^>]*).(bmp|gif|jpeg|jpg|png)('|\")(.*?)>(.*?)<\/a>/i"; $replacement = '<a$1href=$2$3.$4$5 rel="lightbox[roadtrip]"$6>$7'; $content = preg_replace($pattern, $replacement, $content); return $content; }
评论可见
贴不上来…只有放网盘里了…
文件名:内容评论可见.txt
文件大小:2 KB
下载地址:http://1000eb.com/f4sr
评论回复样式
如果主题没有评论回复而使用wordpress默认的话就添加下面的代码
//评论回复邮件 function comment_mail_notify($comment_id) { $comment = get_comment($comment_id); $parent_id = $comment->comment_parent ? $comment->comment_parent : ''; $spam_confirmed = $comment->comment_approved; if (($parent_id != '') && ($spam_confirmed != 'spam')) { $wp_email = 'no-reply@' . preg_replace('#^www\.#', '', strtolower($_SERVER['SERVER_NAME']));//发件人e-mail地址 $to = trim(get_comment($parent_id)->comment_author_email); $subject = '您在 [' . get_option("blogname") . '] 的留言有了回應'; $message = ' <div style="background-color:#fff; border:1px solid #666666; color:#111; -moz-border-radius:8px; -webkit-border-radius:8px; -khtml-border-radius:8px; border-radius:8px; font-size:12px; width:702px; margin:0 auto; margin-top:10px; font-family:微软雅黑, Arial;"> <div style="background:#666666; width:100%; height:60px; color:white; -moz-border-radius:6px 6px 0 0; -webkit-border-radius:6px 6px 0 0; -khtml-border-radius:6px 6px 0 0; border-radius:6px 6px 0 0; "> <span style="height:60px; line-height:60px; margin-left:30px; font-size:12px;"> 您在<a style="text-decoration:none; color:#00bbff;font-weight:600;" href="' . get_option('home') . '">' . get_option('blogname') . ' </a>博客上的留言有回复啦!</span></div> <div style="width:90%; margin:0 auto"> <p>' . trim(get_comment($parent_id)->comment_author) . ', 您好!</p> <p>您曾在 [' . get_option("blogname") . '] 的文章 《' . get_the_title($comment->comment_post_ID) . '》 上发表评论: <p style="background-color: #EEE;border: 1px solid #DDD; padding: 20px;margin: 15px 0;">' . nl2br(get_comment($parent_id)->comment_content) . '</p> <p>' . trim($comment->comment_author) . ' 给您的回复如下: <p style="background-color: #EEE;border: 1px solid #DDD;padding: 20px; margin: 15px 0;">' . nl2br($comment->comment_content) . '</p> <p>您可以点击 <a style="text-decoration:none; color:#00bbff" href="' . htmlspecialchars(get_comment_link($parent_id)) . '">查看回复的完整內容</a></p> <p>欢迎再次光临 <a style="text-decoration:none; color:#00bbff" href="' . get_option('home') . '">' . get_option('blogname') . '</a></p> <p>(此邮件由系统自动发出, 请勿回复.)</p> </div> </div>'; $from = "From: \"" . get_option('blogname') . "\" <$wp_email>"; $headers = "$from\nContent-Type: text/html; charset=" . get_option('blog_charset') . "\n"; wp_mail( $to, $subject, $message, $headers ); //echo 'mail to ', $to, '<br/> ' , $subject, $message; // for testing } } add_action('comment_post', 'comment_mail_notify');如果主题有自己的评论回复提醒那么就到functions.php找到该函数
并将下图蓝色部分后面的按情况替换为图下方的代码
<div style="background-color:#fff; border:1px solid #666666; color:#111; -moz-border-radius:8px; -webkit-border-radius:8px; -khtml-border-radius:8px; border-radius:8px; font-size:12px; width:702px; margin:0 auto; margin-top:10px; font-family:微软雅黑, Arial;"> <div style="background:#666666; width:100%; height:60px; color:white; -moz-border-radius:6px 6px 0 0; -webkit-border-radius:6px 6px 0 0; -khtml-border-radius:6px 6px 0 0; border-radius:6px 6px 0 0; "> <span style="height:60px; line-height:60px; margin-left:30px; font-size:12px;"> 您在<a style="text-decoration:none; color:#00bbff;font-weight:600;" href="' . get_option('home') . '">' . get_option('blogname') . ' </a>博客上的留言有回复啦!</span></div> <div style="width:90%; margin:0 auto"> <p>' . trim(get_comment($parent_id)->comment_author) . ', 您好!</p> <p>您曾在 [' . get_option("blogname") . '] 的文章 《' . get_the_title($comment->comment_post_ID) . '》 上发表评论: <p style="background-color: #EEE;border: 1px solid #DDD; padding: 20px;margin: 15px 0;">' . nl2br(get_comment($parent_id)->comment_content) . '</p> <p>' . trim($comment->comment_author) . ' 给您的回复如下: <p style="background-color: #EEE;border: 1px solid #DDD;padding: 20px; margin: 15px 0;">' . nl2br($comment->comment_content) . '</p> <p>您可以点击 <a style="text-decoration:none; color:#00bbff" href="' . htmlspecialchars(get_comment_link($parent_id)) . '">查看回复的完整內容</a></p> <p>欢迎再次光临 <a style="text-decoration:none; color:#00bbff" href="' . get_option('home') . '">' . get_option('blogname') . '</a></p> <p>(此邮件由系统自动发出, 请勿回复.)</p> </div> </div>'; $from = "From: \"" . get_option('blogname') . "\" <$wp_email>"; $headers = "$from\nContent-Type: text/html; charset=" . get_option('blog_charset') . "\n"; wp_mail( $to, $subject, $message, $headers ); //echo 'mail to ', $to, '<br/> ' , $subject, $message;注意:从图中蓝色部分开始一直到该代码段倒数第二个大括号之间的替换为上方的代码就OK了
PS:2013-02-03
为标签云添加Nofollow
add_filter('wp_tag_cloud','shenqhy_tag_nofollow'); function shenqhy_tag_nofollow($cloud){ $cloud=preg_replace('/<a /','<a rel="nofollow" ',$cloud); return $cloud; }
转载请注明:神奇海域 » WordPress Theme Functions实用代码