Hi there,

Does anyone know how to tell Drupal 7 *not* to use the admin theme for the user edit page?

Specifically, what I m trying to do is to have the default theme when a user edits his own profile, and the admin theme when editing someone else's profile (which typically would be done by an administrator from the admin/people section).

I've tried using hook_custom_theme, which works fine when I tested it for regular pages, but for some reason is ignored when I'm on the user edit page.

function mymodule_custom_theme() {
	global $user;
	// if we're on the user edit page
	if (arg(0) == 'user' && is_numeric(arg(1)) && arg(2) == 'edit') {
		// if the user is editing his own profile
		if (arg(1) == $user->uid) {
			return 'my-default-theme';
		}
		// if editing someone else's profile
		else {
			return variable_get('admin_theme');
		}
	}
	return;
}

Thanks a lot for any suggestions!

Comments

rogueturnip’s picture

Did you ever get a solution to this? I've just run into it also.

lucor’s picture

You may implement the hook_admin_paths_alter hook

function YOUR_MODULE_admin_paths_alter(&$paths) {
    // Treat all user pages as not administrative.
    $paths['user/*'] = FALSE;
}

Hope this helps.

michaellenahan’s picture

Thanks, @lucor - very helpful.

Frederic wbase’s picture

thx for your sollution!

http://www.wbase.be twitter: @wbase_be

afagioli’s picture

Thanks for sharing, lucor
Works great!

Webteam.su’s picture

Thanks!

DashDesai’s picture

Hi Webteam.su,

Going by the time of your comment, I am guessing you have tried Lucor's solution on Drupal 8. I am trying to do the same with Drupal 8.4.4 but it does not seem to work. The API reference pages also don't seem to list hook_admin_paths_alter as a valid hook.

Is there a different way to achieve this in Drupal 8?

FiNeX’s picture

I'm also interested on a official solution in Drupal 8 for both edit and view page, even when logged with administrator.

tory-w’s picture

...6 years later @ lucor. Thanks a bunch!

Lakeside’s picture

Subscribed.