wordpress中functions.php常添加的代码
时间:2021-11-10 11:14:20
//tags标签添加nofollow
add_filter('wp_tag_cloud','tag_cloud_nofollow');
function tag_cloud_nofollow($cloud){
$cloud=preg_replace('/<a /','<a rel="nofollow" ',$cloud);
return $cloud;
}
//隐藏author(作者)
add_filter( 'author_link', 'my_author_link' );
function my_author_link() {
return home_url( '/' );
}
//去除wordpress的版本号
function mt_remove_version() {
return '';
}
add_filter('the_generator', 'mt_remove_version');
//去除wordpress头部window._wpemojiSettings
remove_action( 'admin_print_scripts', 'print_emoji_detection_script');
remove_action( 'admin_print_styles', 'print_emoji_styles');
remove_action( 'wp_head', 'print_emoji_detection_script', 7);
remove_action( 'wp_print_styles', 'print_emoji_styles');
remove_filter( 'the_content_feed', 'wp_staticize_emoji');
remove_filter( 'comment_text_rss', 'wp_staticize_emoji');
remove_filter( 'wp_mail', 'wp_staticize_emoji_for_email');
//wordpress添加友情链接
add_filter('pre_option_link_manager_enabled','__return_true');
//wordpress友情只在首页显示
function rbt_friend_links($output){
if (!is_page()|| is_paged()){
$output = "";
}
return $output;
}
add_filter('wp_list_bookmarks','rbt_friend_links');
//去除头部评论feed
remove_action( 'wp_head', 'feed_links_extra', 3 );
//去除wordpress头部文章feed
remove_action( 'wp_head', 'feed_links', 2 );
//去除wordpress头部shortlink
remove_action('wp_head','wp_shortlink_wp_head',10,0);
remove_action('template_redirect','wp_shortlink_header',11,0);
//移除 WordPress 加载的JS和CSS链接中的版本号
function wpdaxue_remove_cssjs_ver( $src ) {
if( strpos( $src, 'ver=' ) )
$src = remove_query_arg( 'ver', $src );
return $src;
}
add_filter( 'style_loader_src', 'wpdaxue_remove_cssjs_ver', 999 );
add_filter( 'script_loader_src', 'wpdaxue_remove_cssjs_ver', 999 );
//禁用wordpress所有文章类型的修订版本
add_filter( 'wp_revisions_to_keep', 'specs_wp_revisions_to_keep', 10, 2 );
function specs_wp_revisions_to_keep( $num, $post ) {
return 0;
}
//禁止wordpress文章编辑自动保存
add_action( 'wp_print_scripts', 'daxiawp_disable_autosave' );
function daxiawp_disable_autosave(){
wp_deregister_script('autosave');
}
//清理wordpress修改文章时所生成多余的ID
DELETE a,b,c
FROM wp_posts a
LEFT JOIN wp_term_relationships b ON (a.ID = b.object_id)
LEFT JOIN wp_postmeta c ON (a.ID = c.post_id)
WHERE a.post_type = 'revision';
PS:如果直接复制代码添加不成功,是标点符号的大小写问题。请切换小写修改标点符号再保存。