Change the Return URL from the Customizer

Yes, this is possible. On the link, there you create for the customizing view can you add a return parameter with the url, for this option.

I mean, you must change the the link for the Customize Link in the Admin Menu. The follow demonstrate this. I create at fist a link inside the “Appearance” Menu and parse this slug to change the url to custom url, include two parameters.

  1. url – defined for load a specific page in the customizer
  2. return – defined the url for close the customizer, the return url

The important part is the function add_query_arg() to add this parameters to the url.

$login_url = wp_login_url();
$url       = add_query_arg(
    array(
        'url'    => urlencode( $login_url ),
        'return' => admin_url( 'themes.php' ),
    ),
    admin_url( 'customize.php' )
);

The follow source and doing the completely job, include add menu item and change his link. You must load, include this in your theme, plugin.

    <?php # -*- coding: utf-8 -*-

    namespace CustomizeLogin\Admin;

    \add_action( 'admin_menu', '\CustomizeLogin\Admin\add_menu' );
    function add_menu() {

        if ( ! current_user_can( 'customize' ) ) {
            return NULL;
        }

        add_theme_page(
            esc_attr__( 'Customize the Login screen', 'customize-login' ),
            esc_attr__( 'Customize Login', 'customize-login' ),
            'manage_options',
            'customize-login',
            '__return_null()'
        );
    }

    \add_action( 'admin_menu', '\CustomizeLogin\Admin\change_menu_url', 99 );
    function change_menu_url() {

        global $submenu;

        $parent="themes.php";
        $page="customize-login";

        // Create specific url for login view
        $login_url = wp_login_url();
        $url       = add_query_arg(
            array(
                'url'    => urlencode( $login_url ),
                'return' => admin_url( 'themes.php' ),
            ),
            admin_url( 'customize.php' )
        );

        // If is Not Design Menu, return
        if ( ! isset( $submenu[ $parent ] ) ) {
            return NULL;
        }

        foreach ( $submenu[ $parent ] as $key => $value ) {
            // Set new URL for menu item
            if ( $page === $value[ 2 ] ) {
                $submenu[ $parent ][ $key ][ 2 ] = $url;
                break;
            }
        }
    }

Leave a Comment