Skip to content

Add shortcuts to Craft's control panel

When building out a site, I often find find myself clicking through to fields, sections and sites repeatedly. To make this a tiny bit easier, I like to add shortcuts to the Control Panel sidebar for quick access to the things I need most often.

Studio Espresso
Dec 30, 20231 min read

nly prerequisite for this is that you have a Yii module in the project you're building. Then, in the Module's init() function, we'll use the EVENT_REGISTER_CP_NAV_ITEMS event to add one or more links:

use Craft; use craft\web\twig\variables\Cp; use craft\events\RegisterCpNavItemsEvent; Event::on(Cp::class, Cp::EVENT_REGISTER_CP_NAV_ITEMS, function (RegisterCpNavItemsEvent $event) { if (Craft::$app->getConfig()->getGeneral()->allowAdminChanges) { $event->navItems[] = [ 'url' => 'settings/fields', 'label' => 'Fields', 'icon' => '@appicons/field.svg', ]; } });</code></pre></div><div><h2></h2><p>Each item we add needs to have 3 properties: a url, a label and an icon. Url &amp; label speak for themselves, for the icon you can reference an svg icon of your own - or you can piggy-back of the icons that come with Craft. </p>

This is the way I prefer to set things up, as keeping the icons for fields/sections/sites etc the same makes it easier recognise. In /craftcms/cms/src/icons, you can find all the SVG icons that come with Craft CMS, and you can use them through the @appicons alias, like in the example above.

Did you enjoy this article?

Recommend it — Standard Reader surfaces well-loved writing to more readers across the network.

Across the AtmosphereDiscussions