Wordpress在哪里设置"admin_url"?

sim*_*ple 3 php wordpress

基本上需要更改 - admin_url()返回任何想法的值?

fux*_*xia 8

此函数在wp-includes/link-template.php中定义,它提供了一个过滤器:

/**
 * Retrieve the url to the admin area.
 *
 * @package WordPress
 * @since 2.6.0
 *
 * @param string $path Optional path relative to the admin url
 * @return string Admin url link with optional path appended
*/
function admin_url($path = '') {
    $url = site_url('wp-admin/', 'admin');

    if ( !empty($path) && is_string($path) && strpos($path, '..') === false )
        $url .= ltrim($path, '/');

    return apply_filters('admin_url', $url, $path);
}
Run Code Online (Sandbox Code Playgroud)

因此,您可以在主题functions.php中使用自己的过滤器功能来控制输出:

add_filter('admin_url', 'my_new_admin_url');

function my_new_admin_url()
{
    // Insert the new URL here:
    return 'http://example.org/boss/';
}
Run Code Online (Sandbox Code Playgroud)

现在希望所有插件作者都使用这个函数而不是硬编码路径... :)

附录

将此行添加到.htaccess:

Redirect permanent /wp-admin/ http://example.org/new_url/
Run Code Online (Sandbox Code Playgroud)