Skip to content

Instantly share code, notes, and snippets.

View joedolson's full-sized avatar

Joe Dolson joedolson

View GitHub Profile
@joedolson
joedolson / ID24 Demo 5
Created May 23, 2015 17:01
These links will be impossible to find if they're just links; we'll wrap them in an aria landmark element and add a heading.
/*
* Fetch HTML for links and wrap in a container. Add heading and ARIA landmark role.
*
* @param integer $post_ID of current post.
*
* @return full HTML block.
*/
function id24_social_block( $post_ID ) {
$links = id24_create_links( $post_ID );
@joedolson
joedolson / ID24 Demo 6
Created May 23, 2015 17:01
It hardly matters what else we do if this doesn't show up on the page! Use the power of filters and 'the_content' to get crucial data.
/*
* Use WordPress filter 'the_content' to add sharing links into post content.
*
* @param $content The current content of the post.
*
* @return $content The previous content of the post plus social sharing links.
*/
add_filter( 'the_content', 'id24_post_content' );
function id24_post_content( $content ) {
global $post;
@joedolson
joedolson / ID24 Demo 7
Created May 23, 2015 17:01
Social media sharing is about engagement; there's nothing engaging about a bunch of text links. We'll enqueue a stylesheet.
/*
* Register custom stylesheet for ID24 social sharing.
*/
add_action( 'wp_enqueue_scripts', 'id24_register_styles' );
function id24_register_styles() {
wp_register_style( 'id24-icomoon', plugins_url( 'fonts/icomoon.css', __FILE__ ) );
if ( !is_admin() ) {
wp_enqueue_style( 'id24-social-share', plugins_url( 'css/id24.css', __FILE__ ), array( 'dashicons', 'id24-icomoon' ) );
}
}
@joedolson
joedolson / ID24 Demo 8
Created May 23, 2015 17:03
For the purposes of styling, we take another look at the function created in Demo 4. We need some more complexity to style this effectively.
/*
* Generate the HTML links using URLs.
*
* @param integer $post_ID of current post
*
* @return string block of HTML links.
*/
function id24_create_links( $post_ID ) {
$urls = id24_create_urls( $post_ID );
$html = '';
<button class='menu-toggle' aria-controls='menu-main-menu' aria-expanded='false'>
<span class="dashicons dashicons-menu" aria-hidden="true"></span>
<span class='screen-reader-text'><?php _e( 'Expand Menu','textdomain' ); ?></span>
</button>