tag in the document head, and expect WordPress to
* provide it for us.
*/
add_theme_support( 'title-tag' );
/*
* Enable support for Post Thumbnails on posts and pages.
*
* See: https://codex.wordpress.org/Function_Reference/add_theme_support#Post_Thumbnails
*/
add_theme_support( 'post-thumbnails' );
set_post_thumbnail_size( 825, 510, true );
// This theme uses wp_nav_menu() in two locations.
register_nav_menus( array(
'primary' => __( 'Primary Menu', 'readable' ),
'social' => __( 'Social Links Menu', 'readable' ),
) );
/*
* Switch default core markup for search form, comment form, and comments
* to output valid HTML5.
*/
add_theme_support( 'html5', array(
'search-form', 'comment-form', 'comment-list', 'gallery', 'caption'
) );
/*
* Enable support for Post Formats.
*
* See: https://codex.wordpress.org/Post_Formats
*/
add_theme_support( 'post-formats', array(
'aside', 'image', 'video', 'quote', 'link', 'gallery', 'status', 'audio', 'chat'
) );
$color_scheme = readable_get_color_scheme();
$default_color = trim( $color_scheme[0], '#' );
// Setup the WordPress core custom background feature.
add_theme_support( 'custom-background', apply_filters( 'readable_custom_background_args', array(
'default-color' => $default_color,
'default-attachment' => 'fixed',
) ) );
/*
* This theme styles the visual editor to resemble the theme style,
* specifically font, colors, icons, and column width.
*/
add_editor_style( array( 'css/editor-style.css', 'genericons/genericons.css', readable_fonts_url() ) );
}
endif; // readable_setup
add_action( 'after_setup_theme', 'readable_setup' );
/**
* Register widget area.
*
* @since Readable 1.0
*
* @link https://codex.wordpress.org/Function_Reference/register_sidebar
*/
function readable_widgets_init() {
register_sidebar( array(
'name' => __( 'Widget Area', 'readable' ),
'id' => 'sidebar-1',
'description' => __( 'Add widgets here to appear in your sidebar.', 'readable' ),
'before_widget' => '',
'before_title' => '
',
) );
}
add_action( 'widgets_init', 'readable_widgets_init' );
if ( ! function_exists( 'readable_fonts_url' ) ) :
/**
* Register Google fonts for Readable.
*
* @since Readable 1.0
*
* @return string Google fonts URL for the theme.
*/
function readable_fonts_url() {
$fonts_url = '';
$fonts = array();
$subsets = 'latin,latin-ext';
/*
* Translators: If there are characters in your language that are not supported
* by Noto Sans, translate this to 'off'. Do not translate into your own language.
*/
if ( 'off' !== _x( 'on', 'Noto Sans font: on or off', 'readable' ) ) {
$fonts[] = 'Noto Sans:400italic,700italic,400,700';
}
/*
* Translators: If there are characters in your language that are not supported
* by Noto Serif, translate this to 'off'. Do not translate into your own language.
*/
if ( 'off' !== _x( 'on', 'Noto Serif font: on or off', 'readable' ) ) {
$fonts[] = 'Noto Serif:400italic,700italic,400,700';
}
/*
* Translators: If there are characters in your language that are not supported
* by Inconsolata, translate this to 'off'. Do not translate into your own language.
*/
if ( 'off' !== _x( 'on', 'Inconsolata font: on or off', 'readable' ) ) {
$fonts[] = 'Inconsolata:400,700';
}
/*
* Translators: To add an additional character subset specific to your language,
* translate this to 'greek', 'cyrillic', 'devanagari' or 'vietnamese'. Do not translate into your own language.
*/
$subset = _x( 'no-subset', 'Add new subset (greek, cyrillic, devanagari, vietnamese)', 'readable' );
if ( 'cyrillic' == $subset ) {
$subsets .= ',cyrillic,cyrillic-ext';
} elseif ( 'greek' == $subset ) {
$subsets .= ',greek,greek-ext';
} elseif ( 'devanagari' == $subset ) {
$subsets .= ',devanagari';
} elseif ( 'vietnamese' == $subset ) {
$subsets .= ',vietnamese';
}
if ( $fonts ) {
$fonts_url = add_query_arg( array(
'family' => urlencode( implode( '|', $fonts ) ),
'subset' => urlencode( $subsets ),
), '//fonts.googleapis.com/css' );
}
return $fonts_url;
}
endif;
/**
* JavaScript Detection.
*
* Adds a `js` class to the root `` element when JavaScript is detected.
*
* @since Readable 1.1
*/
function readable_javascript_detection() {
echo "\n";
}
add_action( 'wp_head', 'readable_javascript_detection', 0 );
/**
* Enqueue scripts and styles.
*
* @since Readable 1.0
*/
function readable_scripts() {
// Add custom fonts, used in the main stylesheet.
wp_enqueue_style( 'readable-fonts', readable_fonts_url(), array(), null );
// Add Genericons, used in the main stylesheet.
wp_enqueue_style( 'genericons', get_template_directory_uri() . '/genericons/genericons.css', array(), '3.2' );
// Load our main stylesheet.
wp_enqueue_style( 'readable-style', get_stylesheet_uri() );
// Load the Internet Explorer specific stylesheet.
wp_enqueue_style( 'readable-ie', get_template_directory_uri() . '/css/ie.css', array( 'readable-style' ), '20141010' );
wp_style_add_data( 'readable-ie', 'conditional', 'lt IE 9' );
// Load the Internet Explorer 7 specific stylesheet.
wp_enqueue_style( 'readable-ie7', get_template_directory_uri() . '/css/ie7.css', array( 'readable-style' ), '20141010' );
wp_style_add_data( 'readable-ie7', 'conditional', 'lt IE 8' );
wp_enqueue_script( 'readable-skip-link-focus-fix', get_template_directory_uri() . '/js/skip-link-focus-fix.js', array(), '20141010', true );
if ( is_singular() && comments_open() && get_option( 'thread_comments' ) ) {
wp_enqueue_script( 'comment-reply' );
}
if ( is_singular() && wp_attachment_is_image() ) {
wp_enqueue_script( 'readable-keyboard-image-navigation', get_template_directory_uri() . '/js/keyboard-image-navigation.js', array( 'jquery' ), '20141010' );
}
wp_enqueue_script( 'readable-script', get_template_directory_uri() . '/js/functions.js', array( 'jquery' ), '20150330', true );
wp_localize_script( 'readable-script', 'screenReaderText', array(
'expand' => '' . __( 'expand child menu', 'readable' ) . '',
'collapse' => '' . __( 'collapse child menu', 'readable' ) . '',
) );
}
add_action( 'wp_enqueue_scripts', 'readable_scripts' );
/**
* Add featured image as background image to post navigation elements.
*
* @since Readable 1.0
*
* @see wp_add_inline_style()
*/
function readable_post_nav_background() {
if ( ! is_single() ) {
return;
}
$previous = ( is_attachment() ) ? get_post( get_post()->post_parent ) : get_adjacent_post( false, '', true );
$next = get_adjacent_post( false, '', false );
$css = '';
if ( is_attachment() && 'attachment' == $previous->post_type ) {
return;
}
if ( $previous && has_post_thumbnail( $previous->ID ) ) {
$prevthumb = wp_get_attachment_image_src( get_post_thumbnail_id( $previous->ID ), 'post-thumbnail' );
$css .= '
.post-navigation .nav-previous { background-image: url(' . esc_url( $prevthumb[0] ) . '); }
.post-navigation .nav-previous .post-title, .post-navigation .nav-previous a:hover .post-title, .post-navigation .nav-previous .meta-nav { color: #fff; }
.post-navigation .nav-previous a:before { background-color: rgba(0, 0, 0, 0.4); }
';
}
if ( $next && has_post_thumbnail( $next->ID ) ) {
$nextthumb = wp_get_attachment_image_src( get_post_thumbnail_id( $next->ID ), 'post-thumbnail' );
$css .= '
.post-navigation .nav-next { background-image: url(' . esc_url( $nextthumb[0] ) . '); border-top: 0; }
.post-navigation .nav-next .post-title, .post-navigation .nav-next a:hover .post-title, .post-navigation .nav-next .meta-nav { color: #fff; }
.post-navigation .nav-next a:before { background-color: rgba(0, 0, 0, 0.4); }
';
}
wp_add_inline_style( 'readable-style', $css );
}
add_action( 'wp_enqueue_scripts', 'readable_post_nav_background' );
/**
* Display descriptions in main navigation.
*
* @since Readable 1.0
*
* @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 Menu item with possible description.
*/
function readable_nav_description( $item_output, $item, $depth, $args ) {
if ( 'primary' == $args->theme_location && $item->description ) {
$item_output = str_replace( $args->link_after . '', '' . $args->link_after . '', $item_output );
}
return $item_output;
}
add_filter( 'walker_nav_menu_start_el', 'readable_nav_description', 10, 4 );
/**
* Add a `screen-reader-text` class to the search form's submit button.
*
* @since Readable 1.0
*
* @param string $html Search form HTML.
* @return string Modified search form HTML.
*/
function readable_search_form_modify( $html ) {
return str_replace( 'class="search-submit"', 'class="search-submit screen-reader-text"', $html );
}
add_filter( 'get_search_form', 'readable_search_form_modify' );
/**
* Implement the Custom Header feature.
*
* @since Readable 1.0
*/
require get_template_directory() . '/inc/custom-header.php';
/**
* Custom template tags for this theme.
*
* @since Readable 1.0
*/
require get_template_directory() . '/inc/template-tags.php';
/**
* Customizer additions.
*
* @since Readable 1.0
*/
require get_template_directory() . '/inc/customizer.php';
/**
* Lets generate a dynamic date for our footer Copyright.
*
* @since Readable 1.0
*/
function readable_copyright() {
global $wpdb;
$copyright_dates = $wpdb->get_results("
SELECT
YEAR(min(post_date_gmt)) AS firstdate,
YEAR(max(post_date_gmt)) AS lastdate
FROM
$wpdb->posts
WHERE
post_status = 'publish'
");
$output = '';
if($copyright_dates) {
$copyright = "© " . $copyright_dates[0]->firstdate;
if($copyright_dates[0]->firstdate != $copyright_dates[0]->lastdate) {
$copyright .= ' - ' . $copyright_dates[0]->lastdate;
}
$output = $copyright;
}
return $output;
}
/**
* Lets put the Footer credits together ready for output.
*
* @since Readable 1.0
*/
function readable_display_credits() {
$theme_name = wp_get_theme();
$theme_dev = $theme_name->get( 'Author' );
$dev_url = $theme_name->get( 'AuthorURI' );
$power_url = ( 'https://wordpress.org/' );
$text = __('Copyright ', 'readable' ) . readable_copyright().'
';
$text .= sprintf( __( 'Theme: %1$s by %2$s', 'readable' ), $theme_name, '' . $theme_dev .' ' );
$text .= sprintf( __( 'Powered by %s', 'readable' ), 'WordPress' );
echo apply_filters( 'readable_credits_text', $text );
}
add_action( 'readable_credits', 'readable_display_credits' );
/**
* dipslay breadcrumbs.
*
* @since Readable 1.0
*/
function readable_breadcrumbs () {
$separator = '>';
$id = 'breadcrumb';
$class = 'clear';
$home_title = 'Home';
global $post;
if ( !is_front_page() && ( is_single() || is_category() || is_page() || is_tag() || is_day() || is_month() || is_year() || is_author() || get_query_var('paged') || is_search() || is_404() || get_post_format() ) ) {
echo '';
echo '
';
echo '
' . $separator . '
';
if ( is_single() ) {
$categories = get_the_category( $post->ID );
$cat = $categories[0];
if($cat -> parent != 0){
$ancestors = array_reverse( get_ancestors( $cat -> cat_ID, 'category' ) );
foreach($ancestors as $ancestor){
echo '
';
echo '
' . $separator . '
';
}
}
echo '
';
echo '
' . $separator . '
';
echo '
';
} else if ( is_category() ) {
$cat = get_queried_object();
if($cat -> parent != 0){
$ancestors = array_reverse(get_ancestors( $cat -> cat_ID, 'category' ));
foreach($ancestors as $ancestor){
echo '
';
echo '
' . $separator . '
';
}
}
echo '
';
} else if ( is_page() ) {
if( $post->post_parent ){
$anc = get_post_ancestors( $post->ID );
$anc = array_reverse($anc);
foreach ( $anc as $ancestor ) {
$parents .= '
';
$parents .= '
' . $separator . '
';
}
echo $parents;
echo '
';
} else {
echo '
';
}
} else if ( is_tag() ) {
$term_id = get_query_var( 'tag_id' );
$tag = get_tag( $term_id );
echo '
';
} elseif ( is_day() ) {
echo '
';
echo '
' . $separator . '
';
echo '
';
echo '
' . $separator . '
';
echo '
';
} else if ( is_month() ) {
echo '
';
echo '
' . $separator . '
';
echo '
';
} else if ( is_year() ) {
echo '
';
} else if ( is_author() ) {
global $author;
$userdata = get_userdata( $author );
echo '
';
} else if ( is_search() ) {
echo '
';
} else if( get_post_format() ) {
echo '
';
} elseif ( is_404() ) {
echo '
'._e( 'Oops! That page can’t be found.', 'readable' ).'
';
}
echo '
';
}
}