Created
October 20, 2014 13:20
-
-
Save corsonr/0e0a4dfaacf59fdca314 to your computer and use it in GitHub Desktop.
WooCommerce: activate product tabs from URL
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
<?php | |
/** | |
* wc_direct_link_to_product_tabs | |
* | |
* Allows you to create custom URLs to activate product tabs by default, directly from the URL | |
* ex: http://mysite.com/my-product-name#reviews | |
*/ | |
function wc_direct_link_to_product_tabs() { | |
if( is_product() ) { | |
?> | |
<script type="text/javascript"> | |
jQuery(document).ready(function($) { | |
if( window.location.hash ) { | |
// Vars | |
var tab = window.location.hash.replace('#', ''); | |
var tab_content = 'tab-' + tab; | |
// Tabs | |
$( 'li.description_tab' ).removeClass( 'active' ); | |
$( 'li.' + tab + '_tab' ).addClass( 'active' ); | |
// Tabs content | |
$( '#tab-description' ).hide(); | |
$( '#' + tab_content ).show(); | |
} | |
// when the tab is selected update the url with the hash | |
$(".tabs a").click( function() { | |
window.location.hash = $(this).parent('li').attr("class").replace(' active', '').replace('_tab', ''); | |
}); | |
}); | |
</script> | |
<?php | |
} | |
} | |
add_action( 'wp_footer', 'wc_direct_link_to_product_tabs', 30 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Such a task is interesting: so that each tab opens a new url and is not indexed on the neighboring tab, i.e. each tab is a separate page for the search engine.
Интересна такая задача: чтобы каждый таб открывал новый урл и не индексировалася на соседнем табе, т.е. каждый таб был отдельной страницей для поисковика.