This isn't the advice anyone wants to hear. But... consider switching to another theme that supports common functionality like this out-of-the-box: e.g.,
pydata-sphinx-theme
, widely used throughout the open-source data science community. This includes NumPy and SciPy. It doesn't get bigger than that. Personally, I recently switched a sorta popular project I maintain from Furo (...which I strongly advise against, as it's even less configurable than the sphinx-rtd-theme
you're currently using) to pydata-sphinx-theme
. I wish I'd switched sooner. pydata-sphinx-theme
single-handedly catapults Sphinx to the upper crust of the documentation generation community. It's so expert at everything that I kinda wish Sphinx just bundled pydata-sphinx-theme
as its default theme. Seriously. That would've saved me a great deal of grief. Why bother with anything else in 2023 and beyond?
sphinx-book-theme
, which is actually built on top of pydata-sphinx-theme
. It's pydata-sphinx-theme++
, effectively. If you know one, you know the other.
Both trivialize the injection of arbitrary HTML (referred to as an "announcement") at the top of every page:
# In your project's equivalent of "docs/conf.py":
html_theme_options = {
# Announcement banner defined as a string of arbitrary HTML, temporarily
# displayed at the top of each page until the user begins scrolling.
'announcement': (
"<p>"
"Here's a <a href='https://pydata.org'>PyData Announcement!</a>"
"</p>"
),
...
}
HTML is much more useful than mere reStructuredText (reST) in this context of a project banner. HTML admits the possibility of exotic use cases like project-specific advertising – which almost certainly violates the Terms of Services on free-as-in-beer Sphinx hosts like ReadTheDocs (RTD), so please avoid abusing this there. Still, this feature is pretty much the Ultimate Power for informing users about... well, anything!
But, But... What About rst_prolog
?
Yeah. Don't do that. Technically, you can force-feed an announcement at the top or bottom of every page by abusing Sphinx's standard rst_prolog
and rst_epilog
globals as in the accepted answer. Pragmatically, doing so doesn't actually produce a hero banner; it's just a crude hack.
You ideally want your announcement to be an actual banner that sprawls across the full horizontal width of each page. But the output produced by the rst_prolog
and rst_epilog
globals is almost always confined to the central column of your theme. It just looks like any other normal page content. It's certainly better than nothing, but announcements are intended to immediately draw the eye. So, do so!
In short, may the PyData be with you always. \o/