Highlight Current Post in Wordpress Sidebar


/ Published in: JavaScript
Save to your folder(s)

Highlights the current post/page in the Wordpress sidebar.


Copy this code and paste it in your HTML
  1. <script type="text/javascript">
  2. $(document).ready(function() {
  3. // Base URL
  4. var baseUrl = "http://www.yoursite.com/";
  5. // You need to target your sidebar here, change #sidebar to your sidebar identifier (id)
  6. $("#sidebar a").each(function(){
  7. var href = $(this).attr('href').replace(baseUrl,'');
  8. if (href == document.location.pathname) {
  9. $(this).addClass('current');
  10. }
  11. });
  12. });
  13. </script>

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.