返回404用于/Search/Queries-用于Genesis

时间:2016-07-02 作者:ravichopra

我刚刚意识到Wordpress搜索也可以通过以下方式访问http://www.example.com/search/any-search-query. 我之前认为,Wordpress的搜索URL只能作为示例访问。com/?s=任何搜索查询

当有人输入示例时,是否有方法返回404。com/搜索/任何搜索查询。

我用的是Genesis。

1 个回复
SO网友:GaryJ

归根结底,需要通过删除搜索重写规则来禁用搜索slug。我创建了一个插件(也在wp.org repo上):https://github.com/GaryJones/disable-search-slug

以下是主文件:

<?php
/**
 * Disable Search Slug Plugin
 *
 * @package   Gamajo\\DisableSearchSlug
 * @author    Gary Jones
 * @license   GPL-2.0+
 * @copyright 2016 Gamajo Tech
 *
 * @wordpress-plugin
 * Plugin Name:       Disable Search Slug
 * Description:       Stops <code>/search/...</code> URLs from working, resulting in a WordPress 404 page not found.
 * Version:           1.0.1
 * Author:            Gary Jones
 * Text Domain:       disable-search-slug
 * License:           GPL-2.0+
 * License URI:       http://www.gnu.org/licenses/gpl-2.0.txt
 * GitHub Plugin URI: https://github.com/GaryJones/disable-search-slug
 * GitHub Branch:     master
 */

// Wipe out rules for search permalink structure on every page load, in case the
// rules are flushed by WP core, another plugin, a user visiting Settings -> Permalinks.
add_action( \'init\', function() {
    add_filter( \'search_rewrite_rules\', \'__return_empty_array\' );
} );

register_activation_hook( __FILE__ , function() {
    // Wipe out the rules for search permalink structure, on plugin activation.
    add_filter( \'search_rewrite_rules\', \'__return_empty_array\' );
    flush_rewrite_rules();
} );

register_deactivation_hook( __FILE__ , function() {
    // Undo the change in rules to search rules, and flush the rules, on plugin deactivation.
    remove_filter( \'search_rewrite_rules\', \'__return_empty_array\' );
    flush_rewrite_rules();
} );

相关推荐

nothing happen in search form

我想创建搜索表单,但当我搜索时什么都没有发生,这是代码:索引。php: <div class=\"tech-btm\"> <?php get_search_form();?> </div> 搜索表单:<form role=\"search\" method=\"get\" id=\"searchform\" action=\"<?php echo home_url(\'/\')?>\"> &