AI Generated image with a laptop with code on it

How to Dynamically Adjust Sidebar Items in GoHighLevel (GHL) with JavaScript

January 03, 20252 min read

GoHighLevel (GHL) is a powerful all-in-one platform for managing businesses, but sometimes its sidebar layout may not perfectly fit your needs. If you’ve ever wanted to reposition or reorder sidebar elements dynamically, JavaScript is your best friend!

In this guide, we’ll explore how to safely manipulate sidebar items using JavaScript and the MutationObserver API to ensure the code executes only after the DOM is fully ready.

🎯 What Are We Solving?

When trying to move a sidebar divider (#sb_divider-1) one position down, we encounter two common problems:

  1. The DOM is not fully loaded when our script runs.

  2. The sidebar may load dynamically after the initial page load.

Using MutationObserver, we can efficiently wait for the target element to be available before making any changes, without overloading the browser.

💻 The JavaScript Code

Below is the JavaScript code snippet you’ll add to your Custom JS section in GHL:

Custom HTML/CSS/JAVASCRIPT

📝 Explanation of the Code:

  1. MutationObserver: Watches for changes in the DOM to detect when the sidebar items load.

  2. Timeout (setTimeout): Ensures the script stops observing after 10 seconds if the element isn’t found.

  3. insertAdjacentElement: Moves the #sb_divider-1 element right after its next sibling.

  4. Clean-Up: Both the observer and timeout are cleared once the script completes.

🧠 Why Use MutationObserver Instead of setInterval?

✅ Efficient: Only triggers when relevant DOM changes happen.

✅ Less CPU Usage: Avoids constant polling like setInterval.

✅ Scalable: Works well with dynamically loaded content.

While setInterval works, MutationObserver is the more modern and efficient approach.

📹 Video Tutorial: Adding the Script to GoHighLevel

Watch this quick step-by-step tutorial to see how to add this JavaScript code into your GHL instance:

  1. Log in to your Agency Dashboard.

  1. Navigate to Settings (bottom-left menu).

  1. Click on ‘Company’ in the left sidebar.

  1. Select the ‘Whitelabel’ tab.

  1. Scroll down to the ‘Custom JS’ section.

  1. Paste the JavaScript code.

  1. Click ‘Save Changes’.

🎥 [COMING SOON]

🔑 Best Practices

  • Always use a timeout to prevent infinite observers in case of unexpected DOM structures.

  • Test the sidebar after adding the script to ensure it behaves as expected.

  • Regularly check the sidebar structure after GHL updates to avoid breaking changes.

🚦 Potential Issues and Debugging

  • Element Not Found: Ensure the ID (#sb_divider-1) matches your sidebar item.

  • Timeout Triggered: Increase the timeout if your sidebar takes longer to load.

  • Unexpected Behavior: Open Developer Tools > Console and look for any warnings or errors.

💬 Final Thoughts

Using JavaScript and MutationObserver, we’ve efficiently handled dynamic sidebar changes in GoHighLevel. This approach is:

✅ Efficient

✅ Scalable

✅ Clean

If you’re looking to customize your GHL experience further, this script is a solid foundation to build upon.

🤝 Let’s Connect!

  • Have questions? Feel free to reach out!

  • Found this helpful? Share it with your network.

Happy coding! 🚀

📚 Additional Resources

  • JavaScript MutationObserver Documentation

  • GoHighLevel Official Documentation

Let me know if you’d like any adjustments to the blog layout, style, or additional sections. 🚀✨

Back to Blog

Quick Links

Home

About

Services

Press

Book a Consultation

Contact Us

Techanced Marketing

PO Box 22188, Eagan MN 55122

(612) 470-0188

Legal

Privacy Policy

Terms & Conditions

Connect

© {{location.name}} {{right_now.year}}

All Rights Reserved