Created
October 30, 2018 21:08
-
-
Save BinaryMoon/af92b9bcadec87167848ceab1e046f0c to your computer and use it in GitHub Desktop.
Add a 'skip to search' link to the top of a WordPress theme.
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 | |
/** | |
* Plugin Name: Skip to search. | |
* Plugin URI: https://prothemedesign.com | |
* Description: Add "Skip to search" button to site header. | |
* Author: Ben Gillbanks | |
* Version: 1.0 | |
* Author URI: https://prothemedesign.com | |
* Text Domain: sts | |
*/ | |
function sts_footer() { | |
?> | |
<script> | |
(function( $ ) { | |
// Find search widget id. | |
var $search = $( '.search-form:first' ); | |
if ( $search.length < 1 ) { | |
return; | |
} | |
$search.parent( '.widget-wrap' ).attr( 'id', 'skip-to-search' ); | |
var skip_link = $( '<a href="#skip-to-search" class="screen-reader-shortcut"><?php esc_html_e( 'Skip to Search', 'sts' ); ?></a>' ); | |
$( 'a.screen-reader-shortcut[href="#site-content"]' ).after( skip_link ); | |
})( jQuery ); | |
</script> | |
<?php | |
} | |
add_action( 'wp_footer', 'sts_footer' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment