Extending Craft CMS CP with Hooks and Events

In this lesson, we extend the Craft CMS control panel using template hooks and events to display the prominently display current environment.

When I’m work­ing in Craft CMS, I tend to have a lot of open tabs, and some­times tabs from dif­fer­ent envi­ron­ments of the same project. For that rea­son, it’s nice to be able to clear­ly see which envi­ron­ment I’m cur­rent­ly in, so I don’t test or update the incor­rect environment.

To solve this, we’ll build a cus­tom mod­ule that dis­plays the envi­ron­ment in the title tag/​tab name, and as a ban­ner at the top of the con­trol pan­el. Along the way, we will also learn about how to cus­tomize the con­trol pan­el with tem­plate hooks and events.

You might remem­ber that in a pre­vi­ous video, we talked about how to add cus­tom tem­plate hooks in Craft CMS to make it sim­pler to inject cus­tom code into your front-end templates. 

Craft CMS also has tem­plate hooks for inject­ing your own code into the con­trol pan­el templates.

How­ev­er, things have changed over the last cou­ple of major ver­sions of Craft CMS, and the empha­sis is now on using events instead of tem­plate hooks for cus­tomiz­ing Craft CMS con­trol panel.

Let’s take a look at this for some back­ground infor­ma­tion before we jump into how to cus­tomize the con­trol pan­el with our own code.

  1. CP Tem­plate hook removal between Craft 3 and 4: https://​craftcms​.com/​d​o​c​s​/​4​.​x​/​e​x​t​e​n​d​/​u​p​d​a​t​i​n​g​-​p​l​u​g​i​n​s​.​h​t​m​l​#​t​e​m​p​l​a​t​e​-​hooks
  2. CP tem­plate hooks in Craft 4: https://​craftcms​.com/​d​o​c​s​/​4​.​x​/​e​x​t​e​n​d​/​t​e​m​p​l​a​t​e​-​h​o​o​k​s​.html
  3. CP tem­plate hooks in Craft 5: https://​craftcms​.com/​d​o​c​s​/​5​.​x​/​e​x​t​e​n​d​/​t​e​m​p​l​a​t​e​-​h​o​o​k​s​.html

Even though there aren’t that many CP hooks left to use, we’ll use one to manip­u­late the title tag and then move to Events in Craft CMS to add addi­tion­al changes to the Con­trol Panel.

Craft Version
Craft 5
Instructor
Ryan Irelan
Date Published
November 05, 2025