Skip to content
This repository has been archived by the owner on Jan 10, 2018. It is now read-only.

Commit

Permalink
Replace Genericons with SVG icons.
Browse files Browse the repository at this point in the history
  • Loading branch information
samikeijonen committed Oct 14, 2016
1 parent 4f3531f commit 3492881
Show file tree
Hide file tree
Showing 15 changed files with 454 additions and 250 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ Genericons icon font, Copyright 2013-2016 Automattic.com
**License:** GNU GPL, Version 2 (or later)
Source: https://genericons.com/

Font Awesome icons, Copyright Dave Gandy
**License:** SIL Open Font License, version 1.1.
Source: http://fontawesome.io/


## Changelog

Expand Down
4 changes: 2 additions & 2 deletions archive.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@
endwhile;

the_posts_pagination( array(
'prev_text' => '<span class="screen-reader-text">' . __( 'Previous', 'twentyseventeen' ) . '</span>',
'next_text' => '<span class="screen-reader-text">' . __( 'Next', 'twentyseventeen' ) . '</span>',
'prev_text' => twentyseventeen_get_svg( $args = array( 'icon' => 'previous' ) ) . '<span class="screen-reader-text">' . __( 'Previous', 'twentyseventeen' ) . '</span>',
'next_text' => '<span class="screen-reader-text">' . __( 'Next', 'twentyseventeen' ) . '</span>' . twentyseventeen_get_svg( $args = array( 'icon' => 'next' ) ),
) );

else :
Expand Down
128 changes: 128 additions & 0 deletions assets/images/svg-icons.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 2 additions & 1 deletion assets/js/navigation.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
var dropdownToggle = $( '<button />', {
'class': 'dropdown-toggle',
'aria-expanded': false
} ).append( $( '<span />', {
} ).append( twentyseventeenScreenReaderText.icon )
.append( $( '<span />', {
'class': 'screen-reader-text',
text: twentyseventeenScreenReaderText.expand
} ) );
Expand Down
5 changes: 3 additions & 2 deletions comments.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,9 @@
<?php
wp_list_comments( array(
'avatar_size' => 100,
'style' => 'ol',
'short_ping' => true,
'style' => 'ol',
'short_ping' => true,
'reply_text' => twentyseventeen_get_svg( $args = array( 'icon' => 'mail-reply' ) ) . __( 'Reply', 'twentyseventeen' ),
) );
?>
</ol>
Expand Down
4 changes: 2 additions & 2 deletions components/navigation/navigation-top.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@

?>
<nav id="site-navigation" class="main-navigation" role="navigation" aria-label="<?php _e( 'Top Menu', 'twentyseventeen' ); ?>">
<button class="menu-toggle" aria-controls="top-menu" aria-expanded="false"><?php _e( 'Menu', 'twentyseventeen' ); ?></button>
<button class="menu-toggle" aria-controls="top-menu" aria-expanded="false"><?php echo twentyseventeen_get_svg( array( 'icon' => 'bars' ) ); echo twentyseventeen_get_svg( array( 'icon' => 'close' ) ); _e( 'Menu', 'twentyseventeen' ); ?></button>
<?php wp_nav_menu( array(
'theme_location' => 'top',
'menu_id' => 'top-menu',
) ); ?>

<?php if ( twentyseventeen_is_frontpage() || ( is_home() && is_front_page() ) ) : ?>
<button class="menu-scroll-down"><span class="screen-reader-text"><?php _e( 'Scroll Down', 'twentyseventeen' ); ?></span></button>
<button class="menu-scroll-down"><?php echo twentyseventeen_get_svg( array( 'icon' => 'next' ) ); ?><span class="screen-reader-text"><?php _e( 'Scroll Down', 'twentyseventeen' ); ?></span></button>
<?php endif; ?>
</nav><!-- #site-navigation -->
1 change: 1 addition & 0 deletions components/post/content.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
?>

<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<?php if( is_sticky() ) echo twentyseventeen_get_svg( $args = array( 'icon' => 'pinned' ) ); ?>
<header class="entry-header">
<?php
if ( 'post' === get_post_type() ) :
Expand Down
2 changes: 1 addition & 1 deletion footer.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
'menu_class' => 'social-links-menu',
'depth' => 1,
'link_before' => '<span class="screen-reader-text">',
'link_after' => '</span>',
'link_after' => '</span>' . twentyseventeen_get_svg( array( 'icon' => 'chain' ) ),
) );
?>
</nav><!-- .social-navigation -->
Expand Down
9 changes: 6 additions & 3 deletions functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -213,9 +213,6 @@ function twentyseventeen_scripts() {
// Add custom fonts, used in the main stylesheet.
wp_enqueue_style( 'twentyseventeen-fonts', twentyseventeen_fonts_url(), array(), null );

// Add Genericons, used in the main stylesheet.
wp_enqueue_style( 'genericons', get_template_directory_uri() . '/assets/genericons/genericons.css', array(), '3.4.1' );

// Theme stylesheet.
wp_enqueue_style( 'twentyseventeen-style', get_stylesheet_uri() );

Expand All @@ -234,6 +231,7 @@ function twentyseventeen_scripts() {
wp_localize_script( 'twentyseventeen-navigation', 'twentyseventeenScreenReaderText', array(
'expand' => __( 'Expand child menu', 'twentyseventeen' ),
'collapse' => __( 'Collapse child menu', 'twentyseventeen' ),
'icon' => twentyseventeen_get_svg( array( 'icon' => 'expand' ) ),
) );

wp_enqueue_script( 'twentyseventeen-global', get_template_directory_uri() . '/assets/js/global.js', array( 'jquery' ), '20151215', true );
Expand Down Expand Up @@ -318,3 +316,8 @@ function twentyseventeen_post_thumbnail_sizes_attr( $attr, $attachment, $size )
* Customizer additions.
*/
require get_template_directory() . '/inc/customizer.php';

/**
* SVG icons functions and filters.
*/
require get_template_directory() . '/inc/functions-icons.php';
206 changes: 206 additions & 0 deletions inc/functions-icons.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,206 @@
<?php
/**
* SVG icons related functions and filters.
*
* @package WordPress
* @subpackage Twenty_Seventeen
* @since 1.0
*/

/**
* Add SVG definitions to the footer.
*/
function twentyseventeen_include_svg_icons() {

// Define SVG sprite file.
$svg_icons = get_template_directory() . '/assets/images/svg-icons.svg';

// If it exists, include it.
if ( file_exists( $svg_icons ) ) {
echo file_get_contents( $svg_icons );
}

}
add_action( 'wp_footer', 'twentyseventeen_include_svg_icons', 9999 );

/**
* Return SVG markup.
*
* @param array $args {
* Parameters needed to display an SVG.
*
* @param string $icon Required. Use the icon filename, e.g. "facebook-square".
* @param string $title Optional. SVG title, e.g. "Facebook".
* @param string $desc Optional. SVG description, e.g. "Share this post on Facebook".
* }
* @return string SVG markup.
*/
function twentyseventeen_get_svg( $args = array() ) {

// Make sure $args are an array.
if ( empty( $args ) ) {
return esc_html__( 'Please define default parameters in the form of an array.', 'twentyseventeen' );
}

// Define an icon.
if ( false === array_key_exists( 'icon', $args ) ) {
return esc_html__( 'Please define an SVG icon filename.', 'twentyseventeen' );
}

// Set defaults.
$defaults = array(
'icon' => '',
'title' => '',
'desc' => '',
'aria_hidden' => true, // Hide from screen readers.
);

// Parse args.
$args = wp_parse_args( $args, $defaults );

// Set aria hidden.
$aria_hidden = '';

if ( true === $args['aria_hidden'] ) {
$aria_hidden = ' aria-hidden="true"';
}

// Set ARIA.
$aria_labelledby = '';

if ( $args['title'] && $args['desc'] ) {
$aria_labelledby = ' aria-labelledby="title desc"';
}

// Begin SVG markup.
$svg = '<svg class="icon icon-' . esc_html( $args['icon'] ) . '"' . $aria_hidden . $aria_labelledby . ' role="img">';

// If there is a title, display it.
if ( $args['title'] ) {
$svg .= '<title>' . esc_html( $args['title'] ) . '</title>';
}

// If there is a description, display it.
if ( $args['desc'] ) {
$svg .= '<desc>' . esc_html( $args['desc'] ) . '</desc>';
}

// Use absolute path in the Customizer so that icons show up in there.
if ( is_customize_preview() ) {
$svg .= '<use xlink:href="' . get_template_directory_uri() . '/assets/images/svg-icons.svg' . '#icon-' . esc_html( $args['icon'] ) . '"></use>';
} else {
$svg .= '<use xlink:href="#icon-' . esc_html( $args['icon'] ) . '"></use>';
}

$svg .= '</svg>';

return $svg;

}

/**
* Display an SVG icon.
*
* @param array $args Parameters needed to display an SVG.
*/
function twentyseventeen_do_svg( $args = array() ) {
echo twentyseventeen_get_svg( $args );
}

/**
* Display SVG icons in social links menu.
*
* @param string $item_output The menu item output.
* @param WP_Post $item Menu item object.
* @param int $depth Depth of the menu.
* @param array $args wp_nav_menu() arguments.
* @return string $item_output The menu item output with social icon.
*/
function twentyseventeen_nav_menu_social_icons( $item_output, $item, $depth, $args ) {

// Get supported social icons.
$social_icons = twentyseventeen_social_links_icons();

// Change SVG icon inside social links menu if there is supported URL.
if ( 'social' == $args->theme_location ) {
foreach ( $social_icons as $attr => $value ) {
if ( false !== strpos( $item_output, $attr ) ) {
$item_output = str_replace( $args->link_after, '</span>' . twentyseventeen_get_svg( array( 'icon' => esc_attr( $value ) ) ), $item_output );
}
}
}

return $item_output;

}
add_filter( 'walker_nav_menu_start_el', 'twentyseventeen_nav_menu_social_icons', 10, 4 );

/**
* Add dropdown icon if menu item has children.
*
* @param string $title The menu item's title.
* @param object $item The current menu item.
* @param array $args An array of wp_nav_menu() arguments.
* @param int $depth Depth of menu item. Used for padding.
* @return string $title The menu item's title with dropdown icon.
*/
function twentyseventeen_dropdown_icon_to_menu_link( $title, $item, $args, $depth ) {

if ( 'top' == $args->theme_location ) {

foreach ( $item->classes as $value ) {
if ( $value == 'menu-item-has-children' || $value == 'page_item_has_children' ) {
$title = $title . twentyseventeen_get_svg( array( 'icon' => 'expand' ) );
}
}

}

return $title;

}
add_filter( 'nav_menu_item_title', 'twentyseventeen_dropdown_icon_to_menu_link', 10, 4 );

/**
* Returns an array of supported social links (URL and icon name).
*
* @return array $social_links_icons
*/
function twentyseventeen_social_links_icons() {

// Supported social links icons.
$social_links_icons = array(
'codepen.io' => 'codepen',
'digg.com' => 'digg',
'dribbble.com' => 'dribbble',
'dropbox.com' => 'dropbox',
'facebook.com' => 'facebook',
'flickr.com' => 'flickr',
'foursquare.com' => 'foursquare',
'plus.google.com' => 'google-plus',
'github.com' => 'github',
'instagram.com' => 'instagram',
'linkedin.com' => 'linkedin',
'mailto:' => 'envelope-o',
'path.com' => 'path',
'pinterest.com' => 'pinterest-p',
'getpocket.com' => 'get-pocket',
'polldaddy.com' => 'polldaddy',
'reddit.com' => 'reddit-alien',
'skype.com' => 'skype',
'skype:' => 'skype',
'soundcloud.com' => 'soundcloud',
'spotify.com' => 'spotify',
'stumbleupon.com' => 'stumbleupon',
'tumblr.com' => 'tumblr',
'twitch.tv' => 'twitch',
'twitter.com' => 'twitter',
'vimeo.com' => 'vimeo',
'wordpress.org' => 'wordpress',
'wordpress.com' => 'wordpress',
'youtube.com' => 'youtube',
);

return apply_filters( 'twentyseventeen_social_links_icons', $social_links_icons );

}
4 changes: 2 additions & 2 deletions inc/template-tags.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,13 +90,13 @@ function twentyseventeen_entry_footer() {
$categories_list = get_the_category_list( $separate_meta );
// Make sure there's more than one category before displaying.
if ( $categories_list && twentyseventeen_categorized_blog() ) {
echo '<span class="cat-links"><span class="screen-reader-text">' . __( 'Categories', 'twentyseventeen' ) . '</span>' . $categories_list . '</span>'; // WPCS: XSS OK.
echo '<span class="cat-links">' . twentyseventeen_get_svg( $args = array( 'icon' => 'folder-open' ) ) . '<span class="screen-reader-text">' . __( 'Categories', 'twentyseventeen' ) . '</span>' . $categories_list . '</span>'; // WPCS: XSS OK.
}

// Display Tags for posts.
$tags_list = get_the_tag_list( '', $separate_meta );
if ( $tags_list ) {
echo '<span class="tags-links"><span class="screen-reader-text">' . __( 'Tags', 'twentyseventeen' ) . '</span>' . $tags_list . '</span>'; // WPCS: XSS OK.
echo '<span class="tags-links">' . twentyseventeen_get_svg( $args = array( 'icon' => 'hashtag' ) ) . '<span class="screen-reader-text">' . __( 'Tags', 'twentyseventeen' ) . '</span>' . $tags_list . '</span>'; // WPCS: XSS OK.
}

echo '</span>';
Expand Down
4 changes: 2 additions & 2 deletions index.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@
endwhile;

the_posts_pagination( array(
'prev_text' => '<span class="screen-reader-text">' . __( 'Previous', 'twentyseventeen' ) . '</span>',
'next_text' => '<span class="screen-reader-text">' . __( 'Next', 'twentyseventeen' ) . '</span>',
'prev_text' => twentyseventeen_get_svg( $args = array( 'icon' => 'previous' ) ) . '<span class="screen-reader-text">' . __( 'Previous', 'twentyseventeen' ) . '</span>',
'next_text' => '<span class="screen-reader-text">' . __( 'Next', 'twentyseventeen' ) . '</span>' . twentyseventeen_get_svg( $args = array( 'icon' => 'next' ) ),
) );

else :
Expand Down
3 changes: 2 additions & 1 deletion searchform.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,6 @@
<span class="screen-reader-text"><?php echo _x( 'Search for:', 'label', 'twentyseventeen' ); ?></span>
<input type="search" class="search-field" placeholder="<?php echo esc_attr_x( 'Search &hellip;', 'placeholder', 'twentyseventeen' ); ?>" value="<?php echo get_search_query(); ?>" name="s" title="<?php echo esc_attr_x( 'Search for:', 'label', 'twentyseventeen' ); ?>" />
</label>
<button type="submit" class="search-submit"><span class="screen-reader-text"><?php echo _x( 'Search', 'submit button', 'twentyseventeen' ); ?></span></button>
<button type="submit" class="search-submit"><?php echo twentyseventeen_get_svg( array( 'icon' => 'search' ) ); ?><span class="screen-reader-text"><?php echo _x( 'Search', 'submit button', 'twentyseventeen' ); ?></span></button>
</form>

4 changes: 2 additions & 2 deletions single.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@
endif;

the_post_navigation( array(
'prev_text' => '<span class="screen-reader-text">' . __( 'Previous Post', 'twentyseventeen' ) . '</span><span aria-hidden="true" class="nav-subtitle">' . __( 'Previous', 'twentyseventeen' ) . '</span> <span class="nav-title">%title</span>',
'next_text' => '<span class="screen-reader-text">' . __( 'Next Post', 'twentyseventeen' ) . '</span><span aria-hidden="true" class="nav-subtitle">' . __( 'Next', 'twentyseventeen' ) . '</span> <span class="nav-title">%title</span>',
'prev_text' => '<span class="screen-reader-text">' . __( 'Previous Post', 'twentyseventeen' ) . '</span><span aria-hidden="true" class="nav-subtitle">' . __( 'Previous', 'twentyseventeen' ) . '</span> <span class="nav-title"><span class="nav-title-icon-wrapper">' . twentyseventeen_get_svg( $args = array( 'icon' => 'previous' ) ) . '</span>%title</span>',
'next_text' => '<span class="screen-reader-text">' . __( 'Next Post', 'twentyseventeen' ) . '</span><span aria-hidden="true" class="nav-subtitle">' . __( 'Next', 'twentyseventeen' ) . '</span> <span class="nav-title">%title<span class="nav-title-icon-wrapper">' . twentyseventeen_get_svg( $args = array( 'icon' => 'next' ) ) . '</span></span>',
) );

endwhile; // End of the loop.
Expand Down
Loading

0 comments on commit 3492881

Please sign in to comment.