This commit makes some adjustments to a previous fix which broke with new versions of sphinx/theme. Fixes T76453