Skip to content

Help with removing "Edit on Github" option with ReadTheDocs theme #2386

Closed

Description

@brianjking

Hello,

When using http://readthedocs.org with the ReadTheDocs theme is it possible to remove the following elements? If so, how? I couldn't find anything in the documentation about this, if I overlooked it, please point me in the right direction.

  • Edit on Github link in header
  • In footer there's a "Revision #######" after the copyright message. Is there a way to remove this?

Thanks!

Activity

  1. shimizukawa commented on Mar 19, 2016

    @shimizukawa
    Member
  2. xcriptus commented on Mar 19, 2016

    @xcriptus

    Hi,
    you should try to put the following line in your conf.py file

    html_show_sourcelink = False
    

    I've no revision ### after the copyright. If you want to remove the revision in the title bar you can do

    html_theme_options = {
        'display_version': False}
    

    You can also have some fun with creating a _templates directory, look at the layout.html and create a file called _templates/layout.html with your modification. This is not too complex if you have some developement skills. Have a look at the "template" section of sphinx or jinja. For instance the following file add hello world in the side bar, and then "index" in the menu

    {% extends "!layout.html" %}
    {% block sidebartitle %}
        HELLO WORLD
        {{ super() }}
    
    {% endblock %}
    {% block menu %}
        {{ super() }}
        <li class="toctree-l1"><a class="reference internal" href="{{ pathto('genindex') }}">Index</a></li>
        <li class="toctree-l1"><a class="reference internal" href="{{ pathto('py-modindex') }}">Modules index</a></li>
    {% endblock %}
    

    Hope this helps.
    Jean-marie

  3. brianjking commented on Mar 20, 2016

    @brianjking
    Author

    @escribis

    I had already tried html_show_sourcelink = False and it does remove the view page source message when using make html locally on my machine. However, it doesn't do anything about the Edit on Github display when using readthedocs.org.

    The suggestion of using the details below works great when using Sphinx only, but once again, not on readthedocs.org.

    html_theme_options = { 'display_version': False}

    readthedocs github suggested the _templates tweaks you've noted above, however, I don't have the experience necessary and am feeling lost.

    Thanks for your help thus far, anything else you can do would be greatly appreciated.

    Thanks & Cheers!

  4. brianjking commented on Mar 20, 2016

    @brianjking
    Author

    @escribis This is the template I'm using, are you saying I'd copy the source of it, remove the "edit on github" option, which I'm not even sure where it is based on a quick read of it, add this to my local repo and push for RTD to re-build it?

    https://github.com/snide/sphinx_rtd_theme/blob/master/sphinx_rtd_theme/layout.html

    Thanks!

    (If I had to guess the line I'd remove it would be this https://github.com/snide/sphinx_rtd_theme/blob/master/sphinx_rtd_theme/layout.html#L147)

  5. brianjking commented on Mar 20, 2016

    @brianjking
    Author

    @escribis actually, found it in breadcrumbs.html, but using display_github with False doesn't seem to make it work, so please try and explain what all I would need to modify in breadcrumbs.html to get this working.

    Thank you so much!

    https://github.com/snide/sphinx_rtd_theme/blob/master/sphinx_rtd_theme/breadcrumbs.html#L16-L19

  6. JimiC commented on Apr 6, 2016

    @JimiC

    I found myself in your situation where I wanted to remove certain elements from the page. I ended up doing them via javascript. You know if you include

    def setup(app):
        app.add_stylesheet('css/style.css?v=1')
        app.add_javascript('js/script.css?v=1')

    in conf.py and have the corresponding folders under _static, you can style your pages and execute js on them.

  7. brianjking commented on May 9, 2016

    @brianjking
    Author

    Okay, I figured out the "Edit on Github" portion a while ago and thought I'd share my fixes here for anyone else looking to accomplish this.

    I've also documented this on my StackOverflow question.

    Assuming you're using the ReadTheDocs default theme this should work just fine.

    html_context = {
    "display_github": False, # Add 'Edit on Github' link instead of 'View page source'
    "last_updated": True,
    "commit": False,
    }
    
    • Add the breadcrumbs.html file to your tracked files using Git
    • Commit the changes to your conf.py
    • Push to remote Github repo
    • Profit

    References

  8. benjaoming commented on Dec 7, 2017

    @benjaoming
    Contributor

    This doesn't work right now because setting html_context in conf.py is broken. See: #2442

  9. MarSoft commented on Apr 1, 2019

    @MarSoft

    Just for record, the right way is now documented here: https://docs.readthedocs.io/en/stable/guides/remove-edit-buttons.html

    And if you want to only hide these links on some pages (e.g. on pages generated by autosummary which don't have corresponding github file anyway) then you can use that technique in combination with file-level metadata:

    In breadcrumbs.html:

    {%- extends "sphinx_rtd_theme/breadcrumbs.html" %}
    
    {% block breadcrumbs_aside %}
    {% if not meta or meta.get('github_url') != 'hide' %}
    {{ super() }}
    {% endif %}
    {% endblock %}
    

    On the page which should not have github link, add to the very beginning:

    :github_url: hide
    
  10. locked as resolved and limited conversation to collaborators on Aug 6, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions