本日志标题:WordPress的编辑器不能修改别名那就替换成传统编辑器        [2021-5-6]

新下载安装的WordPress编辑器看着比较简介清爽

但不足的地方有两点:操作习惯问题是很多后台编辑人员难以克服的,另外就是有利于优化的文章别名命名功能在新编辑器中不好直接定义。



所以,将这个编辑器替换成传统编辑器就成了解决问题的重点。


解决方法也很简单,两步走:

1、找到当前使用主题的文件夹,具体是在这个目录下:/wp-content/themes/。在在用主题包内打开functions.php

2、选择在functions.php的底部添加以下代码


//禁止Gutenberg编辑器
add_filter('use_block_editor_for_post', '__return_false');
remove_action( 'wp_enqueue_scripts', 'wp_common_block_scripts_and_styles' );



上传覆盖当前主题下的functions.php即可。




其他可以一并添加的配置,可参考添加进functions.php



//页面链接后添加反斜杠
function itbulu_nice_trailingslashit($string, $type_of_url) {
if ($type_of_url != 'single')
$string = trailingslashit($string);
return $string;
}
add_filter('user_trailingslashit', 'itbulu_nice_trailingslashit', 10, 2);

//禁止emojis
function disable_emojis() {
remove_action( 'wp_head', 'print_emoji_detection_script', 7 );
remove_action( 'admin_print_scripts', 'print_emoji_detection_script' );
remove_action( 'wp_print_styles', 'print_emoji_styles' );
remove_action( 'admin_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' );
add_filter( 'tiny_mce_plugins', 'disable_emojis_tinymce' );
}
add_action( 'init', 'disable_emojis' );
function disable_emojis_tinymce( $plugins ) {
if ( is_array( $plugins ) ) {
return array_diff( $plugins, array( 'wpemoji' ) );
} else {
return array();
}
}

//去除加载的css和js后面的版本号
function sb_remove_script_version( $src ){
$parts = explode( '?', $src );
return $parts[0];
}
add_filter( 'script_loader_src', 'sb_remove_script_version', 15, 1 );
add_filter( 'style_loader_src', 'sb_remove_script_version', 15, 1 );
add_action('login_enqueue_scripts','login_protection');

//后台左侧友情链接展示
add_filter( 'pre_option_link_manager_enabled', '__return_true' );

//不自动PING 不自动保存副本
function no_self_ping( &$links ) {
$home = get_option( 'home' );
foreach ( $links as $l => $link )
if ( 0 === strpos( $link, $home ) )
unset($links[$l]);
}
add_action( 'pre_ping', 'no_self_ping' );
remove_action('pre_post_update', 'wp_save_post_revision');
add_action('wp_print_scripts', 'disable_autosave');
function disable_autosave() {
wp_deregister_script('autosave');
}
add_filter( 'pre_option_link_manager_enabled', '__return_true' );
remove_action( 'wp_head', 'wp_generator' );
remove_action( 'wp_head', 'parent_post_rel_link', 10, 0 );
remove_action( 'wp_head', 'start_post_rel_link', 10, 0 );
remove_action( 'wp_head', 'adjacent_posts_rel_link_wp_head', 10, 0 );
remove_action( 'wp_head', 'feed_links_extra', 3 );
remove_action( 'wp_head', 'feed_links', 2 );
remove_action( 'wp_head', 'rsd_link' );
remove_action( 'wp_head', 'wlwmanifest_link' );
remove_action( 'wp_head', 'index_rel_link' );
remove_action( 'wp_head', 'wp_shortlink_wp_head', 10, 0 );

function nice_trailingslashit($string, $type_of_url) {
if ($type_of_url != 'single')
$string = trailingslashit($string);
return $string;
}
add_filter('user_trailingslashit', 'nice_trailingslashit', 10, 2);
if(!function_exists('cwp_remove_script_version')){
function cwp_remove_script_version( $src ){ return remove_query_arg( 'ver', $src ); }
add_filter( 'script_loader_src', 'cwp_remove_script_version' );
add_filter( 'style_loader_src', 'cwp_remove_script_version' );
}
remove_filter('comment_text', 'make_clickable', 9);
remove_filter('the_content', 'wptexturize');

//自动TAGS内链
$match_num_from = 1;
$match_num_to = 2;

add_filter('the_content','tag_link',1);

function tag_sort($a, $b){
if ( $a->name == $b->name ) return 0;
return ( strlen($a->name) > strlen($b->name) ) ? -1 : 1;
}

function tag_link($content){
global $match_num_from,$match_num_to;
$posttags = get_the_tags();
if ($posttags) {
usort($posttags, "tag_sort");
foreach($posttags as $tag) {
$link = get_tag_link($tag->term_id);
$keyword = $tag->name;

$cleankeyword = stripslashes($keyword);
$url = "<a href=\"$link\" title=\"".str_replace('%s',addcslashes($cleankeyword, '$'),__('View all posts in %s'))."\"";
$url .= ' target="_blank" class="tag_link"';
$url .= ">".addcslashes($cleankeyword, '$')."</a>";
$limit = rand($match_num_from,$match_num_to);

$content = preg_replace( '|(<a[^>]+>)(.*)('.$ex_word.')(.*)(</a[^>]*>)|U'.$case, '$1$2%&&&&&%$4$5', $content);
$content = preg_replace( '|(<img)(.*?)('.$ex_word.')(.*?)(>)|U'.$case, '$1$2%&&&&&%$4$5', $content);
$cleankeyword = preg_quote($cleankeyword,'\'');
$regEx = '\'(?!((<.*?)|(<a.*?)))('. $cleankeyword . ')(?!(([^<>]*?)>)|([^>]*?</a>))\'s' . $case;
$content = preg_replace($regEx,$url,$content,$limit);
$content = str_replace( '%&&&&&%', stripslashes($ex_word), $content);
}
}
return $content;
}

//禁止谷歌字体
add_filter( 'gettext_with_context', 'wpdx_disable_open_sans', 888, 4 );
function wpdx_disable_open_sans( $translations, $text, $context, $domain ) {
if ( 'Open Sans font: on or off' == $context && 'on' == $text ) {
$translations = 'off';
}
return $translations;
}

// 关闭 XML-RPC 功能
add_filter('xmlrpc_enabled', '__return_false');

// 屏蔽 REST API
add_filter('rest_enabled', '__return_false');
add_filter('rest_jsonp_enabled', '__return_false');

//移除头部 wp-json 标签和 HTTP header 中的 link
remove_action('wp_head', 'rest_output_link_wp_head', 10 );
remove_action('template_redirect', 'rest_output_link_header', 11 );


//禁止评论有链接
function wp_comment_post( $incoming_comment ) {
$http = '/[href="|rel="nofollow"|http:\/\/|<\/a>]/u';
if(preg_match($http, $incoming_comment['comment_content'])) {
err( "禁止发链接地址!" );
}
return( $incoming_comment );
}
add_filter('preprocess_comment', 'wp_comment_post');

//屏蔽指定关键字搜索 添加后在WP后台可以设置屏蔽搜索关键字
add_action('admin_init', 'uicss_search_ban_key');
function uicss_search_ban_key() {
add_settings_field('uicss_search_key', '搜索关键词屏蔽', 'uicss_search_key_callback_function', 'reading');
register_setting('reading', 'uicss_search_key');
}
function uicss_search_key_callback_function() {
echo '<textarea name="uicss_search_key" rows="10" cols="50" id="uicss_search_key" class="large-text code">' . get_option('uicss_search_key') . '</textarea>';
}
add_action('template_redirect', 'uicss_search_ban');
function uicss_search_ban() {
if (is_search()) {
global $wp_query;
$uicss_search_key = get_option('uicss_search_key');
if ($uicss_search_key) {
$uicss_search_key = str_replace("\r\n", "|", $uicss_search_key);
$BanKey = explode('|', $uicss_search_key);
$S_Key = $wp_query->query_vars;
foreach ($BanKey as $Key) {
if (stristr($S_Key['s'], $Key) != false) {
wp_die('请不要搜索非法关键字');
//header("location:http://www.cnbruce.com");
}
}
}
}
}


在百度搜索完整的WordPress的编辑器不能修改别名那就替换成传统编辑器内容,或者用Google搜索相关的更多内容

By [cnbruce] at 11:36:09 | 评论 [0] | 浏览 [2311] | TrackBack| 返回顶部

About Comments
此篇日志暂时没有相关的说明和评论。:)


Post a Comment
呢称: 验证码: 
禁止笑脸转换 禁止UBB | 缩放输入框:6 5 | [Ctrl+Enter提交](1000个字符限制)