概要説明
ログに見慣れない検索内容が記録されていたときに対応したカスタマイズ。検索機能を使用したときにトップページを強制的に表示するようにすることで検索機能を無効化しています。
~ 目次 ~
WordPress標準の検索機能をしようとした場合にトップページを表示
functions.php
/*----------------------------------------------------
WordPress標準の検索機能をしようとした場合にトップページを表示
----------------------------------------------------*/
if ( !function_exists( 'search_restriction' ) ){
function search_restriction( $query ) {
if ( is_search() && !is_admin() ) {
wp_redirect( get_site_url(), 301 );
exit;
}
}
add_filter( 'parse_query', 'search_restriction' );
add_filter( 'get_search_form', function(){ return null; });
}
検索機能を使用していない場合は無効化がおすすめ
画面上にフォームがなくても直接アクセスで機能実行が可能です。
検索機能に対して攻撃されていると上記のようなログがある場合があります
ウィジェットの標準検索機能を非表示にする
functions.php
/*----------------------------------------------------
WordPress標準の検索ウィジェットを非表示にする
----------------------------------------------------*/
if ( !function_exists( 'remove_search_widget' ) ){
function remove_search_widget() {
unregister_widget('WP_Widget_Search');
}
add_action( 'widgets_init', 'remove_search_widget' );
}



