Posted By

dmatranga on 11/06/09


Tagged

javascript wordpress sidebar jquery item current


Versions (?)

Highlight Current Post in Wordpress Sidebar


 / Published in: JavaScript
 

Highlights the current post/page in the Wordpress sidebar.

  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  

You need to login to post a comment.