Created
February 25, 2024 03:39
-
-
Save wpgaurav/0296ce9d77e0d89efef514a3b6f16f7e to your computer and use it in GitHub Desktop.
Add a floating Link/Button to take reader to Rank Math SEO's Table of Contents on the page.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script> | |
document.addEventListener('DOMContentLoaded', function() { | |
if (document.getElementById('rank-math-toc')) { | |
// Create the new anchor element | |
var tocLink = document.createElement('a'); | |
tocLink.setAttribute('href', '#rank-math-toc'); | |
tocLink.setAttribute('class', 'toc-callout'); | |
tocLink.textContent = 'Table of Contents'; | |
// Insert the new element before the closing body tag | |
document.body.appendChild(tocLink); | |
} | |
}); | |
</script> | |
<style> | |
a.toc-callout { | |
background: #fff; | |
padding: 10px; | |
color: #080808; | |
position: fixed; | |
bottom: 0; | |
right: 0; | |
display: inline; | |
border: 1px solid #ddd; | |
font-weight: 700; | |
} | |
</style> | |
<!-- You can also use the script in a separate JS file and style in customizer CSS or site-editor additional CSS. I recommend using Code Snippets plugin (https://gauravtiwari.org/go/code-snippets/) --> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment