> For the complete documentation index, see [llms.txt](https://docs.allthingsghl.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.allthingsghl.com/membership/courses/sidebar-custom-button.md).

# Sidebar - Custom Button

```javascript
// ****** Sidebar button start ********
(function () {
  const buttons = [
    {
      name: "👉🏻  Upgrade To Next Level  👈🏻",
      id: "btn-1",
      actionURL: "https://www.theghlacademy.com/upgrade",
      style: "fill",
    },

    {
      name: "Become An Affiliate",
      id: "btn-2",
      actionURL: "https://www.theghlacademy.com/affiliate",
      style: "fill",
    },

    {
      name: "View Help Resources",
      id: "btn-3",
      actionURL: "https://www.theghlacademy.com/help",
      style: "fill",
    },
  ];

  const customButtonsStyleSheet = `
    :root {
      --cm-buttons-font-family: 'Roboto', sans-serif;
    
      --custom-cm-btn-border-radius: 5px;
      --custom-cm-btn-padding: 10px 25px;
      --custom-cm-btn-font-size: 16px;
      --custom-cm-btn-font-weight: 700;
      --custom-cm-btn-background-color: rgb(33, 46, 75);
      --custom-cm-btn-font-color: #fff;
      --custom-cm-outline-btn-background-color: transparent;
      --custom-cm-outline-btn-font-color: rgb(24, 15, 120);
      --custom-cm-btn-outline-border: 1px solid rgb(24, 15, 120);
      --transition-all: all 0.3s ease-in;
    }
    
    .cm-buttons-con {
      margin-bottom: 20px !important;
      display: flex !important;
      align-items: stretch !important;
      justify-content: stretch !important;
      flex-direction: column !important;
    }
    
    .cm-buttons-con .cm-custom-button {
      width: 100% !important;
      display: inline-flex !important;
      padding: var(--custom-cm-btn-padding) !important;
      align-items: center !important;
      justify-content: center !important;
      text-align: center !important;
      font-size: var(--custom-cm-btn-font-size) !important;
      font-weight: var(--custom-cm-btn-font-weight) !important;
      border-radius: var(--custom-cm-btn-border-radius) !important;
      text-decoration: none !important;
      transition: var(--transition-all) !important;
    }
    
    .cm-buttons-con .cm-custom-button:not(:last-child) {
        margin-bottom: 15px !important;
    }
    
    .cm-buttons-con .cm-custom-button.fill {
      background-color: var(--custom-cm-btn-background-color) !important;
      color: var(--custom-cm-btn-font-color) !important;
      border: 1px solid transparent !important;
    }
    
    .cm-buttons-con .cm-custom-button.fill:hover {
      background-color: var(--custom-cm-outline-btn-background-color) !important;
      color: var(--custom-cm-outline-btn-font-color) !important;
      border: var(--custom-cm-btn-outline-border) !important;
    }
    
    .cm-buttons-con .cm-custom-button.outline {
      background-color: var(--custom-cm-outline-btn-background-color) !important;
      color: var(--custom-cm-outline-btn-font-color) !important;
      border: var(--custom-cm-btn-outline-border) !important;
    }
    
    .cm-buttons-con .cm-custom-button.outline:hover {
      background-color: var(--custom-cm-btn-background-color) !important;
      color: var(--custom-cm-btn-font-weight) !important;
    }
    
    `;

  const head = document.querySelector("head");
  const style = document.createElement("style");
  style.innerHTML = customButtonsStyleSheet;
  head.append(style);

  const customBtnsCon = document.createElement("div");
  customBtnsCon.className = "cm-buttons-con";

  buttons.forEach((button) => {
    const btn = document.createElement("button");
    const buttonClass = `cm-custom-button ${button.name.toLowerCase()} ${
      button.style
    }`;
    btn.className = buttonClass;
    btn.innerHTML = button.name;
    btn.id = button.id;

    btn.addEventListener("click", () => {
      window.open(button.actionURL, "_blank");
    });

    customBtnsCon.appendChild(btn);
  });

  const getElementByFn = (selector, cb) => {
    const intervalId = setInterval(() => {
      const element = document.querySelectorAll(selector);

      if (element.length === 1) {
        clearInterval(intervalId);
        cb(element[0]);
      }

      if (element.length > 1) {
        clearInterval(intervalId);
        cb(element);
      }
    }, 200);

    setTimeout(function () {
      clearInterval(intervalId);
    }, 20000);
  };

  const runCustomCode = (pathname) => {
    if (!pathname.includes("categories")) return;
    if (customBtnsCon.isConnected) customBtnsCon.remove();

    getElementByFn("#instructor-card", (lessonCard) => {
      const sidebar = lessonCard.parentElement;
      if (!sidebar)
        return console.log(
          "Button Not inserted is because ref element not found"
        );
      sidebar.insertBefore(customBtnsCon, sidebar.childNodes[0]);
    });
  };

  let pathname = "";
  window.addEventListener("DOMNodeInserted", (e) => {
    if (pathname == location.pathname) return;
    pathname = location.pathname;
    runCustomCode(pathname);
  });
})();
// ****** Sidebar button End ********

```

Add the JS code into **Membership > Setting > Advance > Custom JS**

<br>


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.allthingsghl.com/membership/courses/sidebar-custom-button.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
