简体   繁体   English

无论如何通过WP-Config.php做到这一点? (通配卡重定向,但wp-admin除外)

[英]Anyway to do this via WP-Config.php? (Wild Card Redirect except wp-admin)

The goal is to catch all urls and redirect it to homepage. 目标是捕获所有URL并将其重定向到主页。 But will not redirect wp-admin and wp-login.php. 但是不会重定向wp-admin和wp-login.php。

This code works fine and does just that. 这段代码可以正常工作。

in functions.php but Is there anyway to do this pure PHP in wp-config.php ? functions.php中,但是在wp-config.php中是否有做纯PHP的方法呢?


/** WordPress Wild Card Redirect to Home Page */

add_action('template_redirect', 'redirect_to_home');

function redirect_to_home()
{
    if (!is_home() || is_page() || is_single())
    /** If the page is not home */
    {
        /** Redirect to home url */
        wp_redirect(esc_url(home_url('/')));
        exit();
    }
}

wp-config its not the place, create your own plugin and start coding there, so you can reuse in all your developments. wp-config不是地方,创建您自己的插件并在那里开始编码,因此您可以在所有开发中重复使用。

/*
 * Plugin Name: My nice plugin
 * Author: Your name
 */


/** WordPress Wild Card Redirect to Home Page */

add_action('template_redirect', 'redirect_to_home');

function redirect_to_home()
{
    if (!is_home() || is_page() || is_single())
    /** If the page is not home */
    {
        /** Redirect to home url */
        wp_redirect(esc_url(home_url('/')));
        exit();
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM