首页 >

自定义WordPress网站屏蔽搜索特殊关键词的方法

以下是无插件直接定制的解决方案,让我们来看看解决方案:

第一、添加Functions.php

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 '';}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", "
		

  • 暂无相关文章