April 20, 2008
Creating an Admin Bar for Expression Engine
A while back I got tired of now having a way to access the control panel from the front-end of my site. I decided to investigate the best way to create this type of functionality. I had no doubts that ExpressionEngine contained a way, since it’s such a powerful system, but I wasn’t sure how. Here’s what I found.
ExpressionEngine uses a variable called group_id to determine what group the currently logged-in user is in. In most cases, a group_id of 1 means you’re a Super Admin, meaning you have access to the control panel.
The other piece of the puzzle is finding out how to link to certain areas of the control panel. I was not able to find any information about this in the EE Documentation, so i’ll present my findings here.
When you’re logged in, look at the end of the URL and you should see something like “…&C=publish”. Each area of the admin has a C value that corresponds to it (as well as some other variables in more complicated areas). The only variable that should be disregarded is “S” which stands for your session_id and is irrelevant to our goals.
Here are a couple of common ones:
- Publish tab - C=publish
- Edit tab - C=edit
- Templates tab - C=templates
- Admin tab - C=admin
- Log-out - C=logout
And a couple more complicated (but very useful) ones:
- New Post in Weblog 1 - C=publish&M=entry_form&weblog_id=1
- Edit Post 88 - C=edit&M=edit_entry&weblog_id=1&entry_id=88
Now that we know how to only show this bar to our Super Admin users, as well as the urls we need to link to, we can add in our code to the template.
Here’s the code i’m using. You’re very welcome to use this code in your own sites, as it should work perfectly without any customization.
{if group_id == 1}
<!-- if user is in Super Admin (group #1) -->
<div class="admin_bar">
<!-- the container for our admin bar -->
<ul>
<li>Welcome {screen_name}!</li>
<!-- welcome our current logged in user by their screen name -->
<li><a href="{site_url}system" title="Access the CP">
Control Panel</a></li>
<li><a href="{site_url}system/index.php?C=publish
&M=entry_form&weblog_id=1" title="Write a New Post">
New Post</a></li>
<li><a href="{site_url}system/index.php?C=edit">
Edit Posts</a></li>
<li><a href="http://expressionengine.com/docs/">
Documentation</a></li>
<li><a href="{site_url}system/index.php?C=logout">
Log Out</a></li>
</ul>
</div>
{/if}
And that’s it! You’ve just added your very own Admin bar. I would make sure this is working for your specific set up, and double check things like the group_id just to be safe.
One thing that has always annoyed me was that you don’t stay logged in for very long, therefore the bar disappears pretty often. If you’d like to remain logged in much longer than the default configuration allows, there is an easy way to enable that.
Simply go to Admin → System Preferences → Security & Session Preferences and set the Control Panel Session Type to “Cookies only.”
This will keep you logged in longer, but you will lose some security if you log in on a public computer and forget to log out. The implications are minor, but still there.
I hope you’ve enjoyed this code sample and I hope it inspires even more cool ideas, and be sure to blog them so we can all enjoy. Let me know in the comments if you’ve got questions or other feedback.
Update:
There are some variables you’ll want to double-check before using this on your site:
- group_id - Double check that this ID is your super admin group
- system/ - Make sure that you change “system” to whatever folder you’re using. “system” is the default configuration, but many people change it.
- weblog_id - You’ll want to make sure that this is the ID of the weblog you’d like to post/edit from. Again, under default configuration, this should be 1, but this could likely change if you have multiple “weblogs” on your install.
Also if you’re trying to use something like this in the weblog entries tag, comments tag, or within other member-related tags you’ll need to add the prefix “logged_in_” to your group_id, screen_name and other member-related variables. This specifies that you only want the info about the logged in user and not the user who posted the current content.








Nice. It’s way easy to do in wp though… it’s weird that EE doesn’t have that documented.
Man, that’s awesome; it’s too bad I just closed my blog in favour of Tumblr.
Very nice Josh, and very useful. Sure I will use it for my website.
Thanks man.
Hi Josh, Hey you really should contact LisaWess over there on the EE forums about adding that to the wiki. This belongs in the wiki for sure. Nice stuff!!
Nice writeup. You might consider using “logged_in_group_id” to avoid any confusion in an {exp:weblog:entries} syntax. Also, there is some info available in the wiki on how to do that, but it’s still nice to have it all in one place.
Hi Josh,
Interesting read. Just found the link on the EE forums to this write-up. I already do this kind of thing on sites and I also use a Global Variable using the Fresh Variables module so that I can simply set a toggle switch so that when I am working on the initial design of the site I can turn the bar off as I am going to be in the control panel anyway but then when the site goes live I can toggle it to turn the admin links on and then have easy access to items just as you have above.
One thing to note though - you said that the code should work perfectly without customisation. It should do yes except perhaps a little warning note about the New Post link as weblog_id=1 may not be ideal for some or people with multiple weblogs may wonder what is going on ;-)
Just a thought though.
Nice little write up.
Best wishes,
Mark
Thanks for the great comments guys!
@Ty
I was wondering if I should do that. If that’s something that people would find useful then i’ll do it for sure.
@Ingmar
Thanks! I’ll make a note of this. I ran into trouble with that when I was working on inline editing, but I figured since people are most likely using this outside of those tags it wouldn’t be necessary. I actually just found that wiki link last night, but thought it didn’t really explain enough about linking to the CP functions.
@Mark
That’s an interesting insight. I’m using Fresh Variables for some other things, but that’s a cool use of it as well. I should definitely clarify some variables to double check before using it on a site. Thanks for the reminding me!
Nice writeup Josh. I could’ve sworn I saw this under the User Module docs but I could be wrong. I want to add in functionality on my blog to edit a specific post or comment next. :)
Josh, I suppose you’ve got an account on the EE site? You can then contribute to the wiki. It’s a community effort, no need to ask anybody… I for one would like to see that written up in a nice article. No pressure, though :-P