Answers.Body: <p><strike>Not possible, unfortunately – you'll have to use JavaScript/jQuery to hack it in.</strike></p>
  
  <p>See Brad's answer for a canonical solution. It's also possible to use JavaScript/jQuery to accomplish what you want – something like this should do the trick:</p>
  
  <pre><code>$('input[name="revisionNotes"]').before('&lt;a href="'+Craft.getCpUrl('yourcustomroute')+'" class="btn"&gt;Button label&lt;/a&gt;');
  </code></pre>
  
  <p>The above will inject a button, just above the revision notes input in the sidebar, pointing to <code>/admin/yourcustomroute</code>.</p>
  
  <p>As for getting the ID, the easiest way to do that is to use jQuery to pull the hidden input named <code>entryId</code>:</p>
  
  <pre><code>var entryId = $('input[type="hidden"][name="entryId"]').val();
  </code></pre>
  
  <p>Obviously, a new entry that hasn't been saved yet doesn't have an entry ID, so you might want to opt for not rendering the button if jQuery can't find the the hidden input, or if its value is empty. So putting it together:</p>
  
  <pre><code>var entryId = $('input[type="hidden"][name="entryId"]').val();
  
  if (entryId) {
      $('input[name="revisionNotes"]').before('&lt;a href="'+Craft.getCpUrl('yourcustomroute/'+entryId)+'" class="btn"&gt;Button label&lt;/a&gt;');
  }
  </code></pre>
  
  <p>Note that if the URL should point to an <a href="https://craftcms.com/docs/plugins/controllers" rel="nofollow noreferrer">action</a> rather than a CP resource, you can use <code>Craft.getActionUrl()</code> over <code>Craft.getCpUrl()</code>, or if its a frontend resource, you can use <code>Craft.getSiteUrl()</code> instead.</p>
  
  <p>You can run the above command in your browser's console to test it out. To run it with your plugin, you'll need to add it to a JavaScript file included in your plugin's <code>/resources</code> folder, and add the file to Craft's Control Panel like this (in your plugin's main class file):</p>
  
  <pre><code>public function init ()
  {
      if (craft()-&gt;request-&gt;isCpRequest()) {
          craft()-&gt;templates-&gt;includeJsResource('yourPluginHandle/script.js');
      }
  }
  </code></pre>
  
  <p>For more info on adding JavaScript to Craft's Control Panel, see <a href="https://craftcms.stackexchange.com/a/270/1098">this thread</a>.</p>
  
  <p>Also, be advised that using this method makes your code entirely dependent on the DOM structure of Craft's Control Panel, which can change at any time, possibly breaking your implementation.</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>It would appear this is possible without resorting to JS hacks after all, as per Brad's answer below. I'll leave this answer up anyway, as it could be a useful proof of concept for injecting HTML into other parts of the Control Panel.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-04-05T14:47:03.740Z
Answers.Text: Completely not documented, but there is a template hook you can use in `craft/app/templates/entries/_edit.html` called `{% hook "cp.entries.edit.right-pane" %}`
Answers.UserDisplayName: Brad Bell
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-04-05T16:30:42.497Z
Answers.Text: I suppose I'll add that as an answer.
Answers.UserDisplayName: Brad Bell
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-04-05T11:56:34.877Z
Answers.LastActivityDate: 2016-04-05T23:25:51.620Z
Answers.LastEditDate: 2017-04-13T12:51:00.200Z
Answers.UserDisplayName: Mats Mikkel Rummelhoff
Answers.Body: <p>You can add custom HTML in exactly the spot you’re hoping to, using the (undocumented) <code>cp.entries.edit.right-pane</code> <a href="https://craftcms.com/classreference/services/TemplatesService#hook-detail">template hook</a>.</p>
  
  <p>To use it, add this to your plugin’s primary class:</p>
  
  <pre class="lang-php prettyprint-override"><code>public function init()
  {
      craft()-&gt;templates-&gt;hook('cp.entries.edit.right-pane', function(&amp;$context) {
          /** @var EntryModel $entry **/
          $entry = $context['entry'];
  
          // Make sure this is the correct section
          if ($entry-&gt;sectionId == 5) {
              // Return the button HTML
              $url = UrlHelper::getUrl('some/path/'.$entry-&gt;id);
              return '&lt;a href="'.$url.'" class="btn"&gt;My Button!&lt;/a&gt;';
          }
      });
  }
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-06-14T12:31:15.207Z
Answers.Text: Brad B. Why would you hide such an awesome thing? :)
Answers.UserDisplayName: Krzysztof Boduch
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-08-08T18:27:15.610Z
Answers.Text: In Craft 3 this is now `Craft::$app->getView()->hook('cp.entries.edit.details', function(array &$context)` ... worked great for me!
Answers.UserDisplayName: Nate Beaty
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2023-09-08T10:24:42.833Z
Answers.Text: Here is the list of hooks : https://craftcms.com/docs/3.x/extend/template-hooks.html#control-panel-template-hooks
Answers.UserDisplayName: emilie zawadzki
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-04-05T16:31:43.683Z
Answers.LastActivityDate: 2016-04-05T23:01:28.197Z
Answers.LastEditDate: 2016-04-05T23:01:28.197Z
Answers.UserDisplayName: Brad Bell
Body: <p>I would like to add a custom button in the right section of a channels entry form in the CMS. 
  The this button needs to go to a custom url of the plugin that I have created. The link should contain entry ID so that I can use this ID in my plugin.
  <a href="https://i.sstatic.net/Ckv4N.png" rel="noreferrer"><img src="https://i.sstatic.net/Ckv4N.png" alt="Can I add a custom button here? "></a></p>
  
Tags: <plugin-development>
Title: How to add a custom button at the right section of an entry?
ThreadText: # How to add a custom button at the right section of an entry?
  
  (Asked by: username_0 on 2016-04-05)
  
  I would like to add a custom button in the right section of a channels entry form in the CMS.
  The this button needs to go to a custom url of the plugin that I have created. The link should contain entry ID so that I can use this ID in my plugin.
  [![Can I add a custom button here? ](https://i.sstatic.net/Ckv4N.png)](https://i.sstatic.net/Ckv4N.png)
  
  **Tags:** plugin-development
  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_2 on 2016-04-05. Score: 13 | Accepted answer
  
  You can add custom HTML in exactly the spot you’re hoping to, using the (undocumented) `cp.entries.edit.right-pane` [template hook](https://craftcms.com/classreference/services/TemplatesService#hook-detail).
  
  To use it, add this to your plugin’s primary class:
  
  ```php
  public function init()
  {
      craft()->templates->hook('cp.entries.edit.right-pane', function(&$context) {
          /** @var EntryModel $entry **/
          $entry = $context['entry'];
  
          // Make sure this is the correct section
          if ($entry->sectionId == 5) {
              // Return the button HTML
              $url = UrlHelper::getUrl('some/path/'.$entry->id);
              return '<a href="'.$url.'" class="btn">My Button!</a>';
          }
      });
  }
  
  ```
  
  > **Comments:**
  > **username_3**: username_2 B. Why would you hide such an awesome thing? :)  
  > **username_4**: In Craft 3 this is now `Craft::$app->getView()->hook('cp.entries.edit.details', function(array &$context)` ... worked great for me!  
  > **username_5**: Here is the list of hooks : https://craftcms.com/docs/3.x/extend/template-hooks.html#control-panel-template-hooks  
  
  ---
  
  ### Answer by username_1 on 2016-04-05. Score: 2
  
  Not possible, unfortunately – you'll have to use JavaScript/jQuery to hack it in.
  
  See username_2's answer for a canonical solution. It's also possible to use JavaScript/jQuery to accomplish what you want – something like this should do the trick:
  
  ```
  $('input[name="revisionNotes"]').before('<a href="'+Craft.getCpUrl('yourcustomroute')+'" class="btn">Button label</a>');
  
  ```
  
  The above will inject a button, just above the revision notes input in the sidebar, pointing to `/admin/yourcustomroute`.
  
  As for getting the ID, the easiest way to do that is to use jQuery to pull the hidden input named `entryId`:
  
  ```
  var entryId = $('input[type="hidden"][name="entryId"]').val();
  
  ```
  
  Obviously, a new entry that hasn't been saved yet doesn't have an entry ID, so you might want to opt for not rendering the button if jQuery can't find the the hidden input, or if its value is empty. So putting it together:
  
  ```
  var entryId = $('input[type="hidden"][name="entryId"]').val();
  
  if (entryId) {
      $('input[name="revisionNotes"]').before('<a href="'+Craft.getCpUrl('yourcustomroute/'+entryId)+'" class="btn">Button label</a>');
  }
  
  ```
  
  Note that if the URL should point to an [action](https://craftcms.com/docs/plugins/controllers) rather than a CP resource, you can use `Craft.getActionUrl()` over `Craft.getCpUrl()`, or if its a frontend resource, you can use `Craft.getSiteUrl()` instead.
  
  You can run the above command in your browser's console to test it out. To run it with your plugin, you'll need to add it to a JavaScript file included in your plugin's `/resources` folder, and add the file to Craft's Control Panel like this (in your plugin's main class file):
  
  ```
  public function init ()
  {
      if (craft()->request->isCpRequest()) {
          craft()->templates->includeJsResource('yourPluginHandle/script.js');
      }
  }
  
  ```
  
  For more info on adding JavaScript to Craft's Control Panel, see [this thread](https://craftcms.stackexchange.com/a/270/1098).
  
  Also, be advised that using this method makes your code entirely dependent on the DOM structure of Craft's Control Panel, which can change at any time, possibly breaking your implementation.
  
  **EDIT**
  
  It would appear this is possible without resorting to JS hacks after all, as per username_2's answer below. I'll leave this answer up anyway, as it could be a useful proof of concept for injecting HTML into other parts of the Control Panel.
  
  > **Comments:**
  > **username_2**: Completely not documented, but there is a template hook you can use in `craft/app/templates/entries/_edit.html` called `{% hook "cp.entries.edit.right-pane" %}`  
  > **username_2**: I suppose I'll add that as an answer.  
  
  ---
  
  