Last active
March 4, 2017 07:41
-
-
Save fjarrett/925f84475a8e8c99db6c78afdcc5e1e6 to your computer and use it in GitHub Desktop.
Turn the entire Hero section into a clickable link
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 | |
/** | |
* Turn the entire Hero section into a clickable link. | |
* | |
* Put this hook inside your own must-use plugin, and replace the URL assigned to the `$hero_link` variable. | |
* | |
* How to make one: https://github.com/godaddy/wp-primer-theme/wiki/Customizing-Primer-with-hooks | |
*/ | |
add_action( 'wp_print_footer_scripts', function () { | |
if ( ! is_front_page() || ! is_active_sidebar( 'hero' ) ) { | |
return; | |
} | |
$hero_link = 'http://example.com/product-page/'; // <--- PUT YOUR URL HERE | |
?> | |
<style type="text/css">.hero:hover { cursor: pointer; }</style> | |
<script type="text/javascript">var $primerHero = document.getElementsByClassName("hero")[0]; if ( "undefined" !== typeof $primerHero ) { $primerHero.onclick = function() { window.location.href = "<?php echo esc_url( $hero_link ); ?>"; }; }</script> | |
<?php | |
} ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment