PHP code to redirect Login to "Pages"

Can anyone help me with a piece of php code that I could use to prevent the initial display of the Dashboard for 'sub-site' Admin logins (I have a dedicated Theme for sub-sites, in which I would like to place the code in the theme-functions.php!).

My wish is that an Admin login always display the "Home Page" Text Editor (when using the above specific Theme) upon entering the Admin Menu Display/Text Editor.

Hope this makes sense?

Thankiing you in advance.



  • Rupok
    • Support Ninja

    Hi johnv,

    Thanks for asking. I'm really sorry but I'm not sure if I understood the following part:

    My wish is that an Admin login always display the "Home Page" Text Editor (when using the above specific Theme) upon entering the Admin Menu Display/Text Editor.

    Did you mean that when an admin logs in, he will be taken to the back-end editor page for the theme homepage? If yes, then what page do you want to show after login for other user roles? And if not, can you please explain a bit more so we can provide a better solution?

    I'm looking forward to hearing from you and resolving this issue as soon as possible.

    Have a nice day. Cheers!

  • john
    • Site Builder, Child of Zeus

    Hi Rupok .

    Thank you for your reply.

    I found it a 'wee bit' confusing myself, when trying to write it!!!!!

    All the sub-sites covered by the Theme I wish to amend, only have one page!

    So (of course) this is the 'Home Page'. The home page (on all sites) are call :- "Back of Card".

    Hope this help!

    In the WP Admin Editor I have hidden the Dashboard from display,ing in the WP Admin Editor Sidebar (Menu still displays for certain Plugins/Page/etc).

    When I type in:- I get the "Dashboard" which I wish to Hide form Admins!

    If these logins could be taken to the "Back of Card" view (open in editor) that would serve my purpose!!

    Hoping this clarifies somewhat!


  • john
    • Site Builder, Child of Zeus

    Hi Kasia.

    Thank you for your reply!

    I am not so concerned with the main site. So this uses a different Theme!

    I am using the "Pro-site" plugin and the "Blog Template Plugin", which employs a dedicated Theme. This is why I would prefer to put Php code in the theme-function Php.

    Thus, the function here is that all users signed up for a 'sub-site'; are provided with a 'one page only' 'templated' site upon login.

    Thus the Wordpress Dashboard ; essentially; gives the impression of being redundant in "my scheme of things" for this particular install!

    Therefore, for a user ; upon login; to be taken straight to the single Admin 'Page Editor' Page would a very convenient arrangement, I suspect!!!!

    Hope this offers some clarification into my scrambled description?

    Do please ask foe more explanation attempts, if needs be!


  • Adam Czajczyk
    • Support Gorilla

    Hi @johnvocehome!

    I did it a try and I came up with some code. If I correctly understood you goal, it should work. What it does is:

    - it fires up only upon login
    - if a logged in user is a super-admin, code does nothing
    - if a logged in user is a user of any role other than super-admin that doesn't have his/her own site (blog), it also doesn't do anything
    - if a logged in user has a blog it then:

    * checks list of blogs of that user (where he/she is an administrator);
    * if there's more than one blog, it takes the most recent one created;
    * it checks if there's a static homepage set and takes an id of that page
    * if there is such page set, it redirects to the WP editor in WP admin area to edit that page

    Give it a try and let's see :slight_smile: I'd suggest adding it rather as an mu plugin than putting it into "functions.php" file of the theme. To use it as MU plugin simply:

    - create an empty file with a .php extension (e.g. "my-admins-edit-redirect.php")
    - using "clean text" editor such as e.g. Notepad++, Sublime or similar, put this code inside:

    function wpmu_redirect_to_homepage_edit($redirect_org, $request, $user) {
    	if (!is_super_admin()) {
    		if ( isset( $user->roles ) && is_array( $user->roles ) ) {
    		//check for admins
    			if ( in_array( 'administrator', $user->roles ) ) {
    				$user_id = $user->ID;
    				$role = 'administrator';
    				$blogs = get_blogs_of_user( $user_id );
    				foreach ( $blogs as $blog_id => $blog ) {
    					// Get the user object for the user for this blog.
    					$user = new WP_User( $user_id, '', $blog_id );
    					// Remove this blog from the list if the user doesn't have the role for it.
    					if ( ! in_array( $role, $user->roles ) ) {
    						unset( $blogs[ $blog_id ] );
    				if ( count( $blogs) > 1) {
    					$blogs = array_reverse( $blogs );
    					$blogs = $blogs[1];
    				switch_to_blog( $blogs->userblog_id);
    				$homepage_id = get_option( 'page_on_front' );
    				$redirect_to = get_site_url( $blogs->userblog_id ) . '/wp-admin/post.php?post=' . $homepage_id . '&action=edit';
    				return $redirect_to;
    		else {
    			return $redirect_org;
    	else {
    		return $redirect_org;
    add_filter( 'login_redirect' , 'wpmu_redirect_to_homepage_edit', 10, 3);

    - save the file and upload it to the /wp-content/mu-plugins folder of your multisite install; if there's no "mu-plugins" folder inside "wp-content" folder, just create an empty one.

    Best regards,

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.