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.
*
* @link http://codex.wordpress.org/Function_Reference/add_theme_support#Post_Thumbnails
*/
add_theme_support( 'post-thumbnails' );
set_post_thumbnail_size( 833, 0, true );
// This theme uses wp_nav_menu() in one location.
register_nav_menus( array(
'primary' => __( 'Primary Menu', 'afterlight' ),
'social' => __( 'Social Links Menu', 'afterlight' ),
) );
/*
* 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',
) );
// Set up the WordPress core custom background feature.
add_theme_support( 'custom-background', apply_filters( 'afterlight_custom_background_args', array(
'default-attachment' => 'fixed',
'default-color' => '1a1a1a',
'default-image' => get_template_directory_uri() . '/images/background.jpg',
'default-position-x' => 'center',
'default-repeat' => 'no-repeat',
'wp-head-callback' => 'afterlight_custom_background_cb'
) ) );
/*
* This theme styles the visual editor to resemble the theme style,
* specifically font, colors, icons, and column width.
*/
add_editor_style( array( 'editor-style.css', 'genericons/genericons.css', afterlight_fonts_url() ) );
}
endif; // afterlight_setup
add_action( 'after_setup_theme', 'afterlight_setup' );
if ( ! function_exists( 'afterlight_custom_background_cb' ) ) :
/**
* Add a wp-head callback to the custom background
*
* @since Afterlight 1.0
*/
function afterlight_custom_background_cb() {
$image = get_background_image();
$color = get_background_color();
if ( empty ( $image ) && empty ( $color ) ) {
return;
}
if ( ! empty ( $image ) ) {
_custom_background_cb();
}
if ( ! empty ( $color ) && '1a1a1a' != $color ) { ?>
__( 'Widget Area', 'afterlight' ),
'id' => 'sidebar-1',
'description' => __( 'Add widgets here to appear in your off-screen panel.', 'afterlight' ),
'before_widget' => '',
'before_title' => '
',
) );
}
add_action( 'widgets_init', 'afterlight_widgets_init' );
if ( ! function_exists( 'afterlight_fonts_url' ) ) :
/**
* Register Google fonts for afterlight.
*
* @since Afterlight 1.0
*
* @return string Google fonts URL for the theme.
*/
function afterlight_fonts_url() {
$fonts_url = '';
$fonts = array();
$subsets = 'latin,latin-ext';
/* translators: If there are characters in your language that are not supported by Playfair Display, translate this to 'off'. Do not translate into your own language. */
if ( 'off' !== _x( 'on', 'Playfair Display font: on or off', 'afterlight' ) ) {
$fonts[] = 'Playfair Display:400,700,400italic,700italic';
}
/* translators: If there are characters in your language that are not supported by Lato, translate this to 'off'. Do not translate into your own language. */
if ( 'off' !== _x( 'on', 'Lato font: on or off', 'afterlight' ) ) {
$fonts[] = 'Lato:400,700,400italic,700italic';
}
/* 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', 'afterlight' ) ) {
$fonts[] = 'Inconsolata:400';
}
if ( $fonts ) {
$fonts_url = add_query_arg( array(
'family' => urlencode( implode( '|', $fonts ) ),
'subset' => urlencode( $subsets ),
), 'https://fonts.googleapis.com/css' );
}
return $fonts_url;
}
endif;
/**
* JavaScript Detection.
*
* Adds a `js` class to the root `` element when JavaScript is detected.
*
* @since Afterlight 1.0
*/
function afterlight_javascript_detection() {
echo "\n";
}
add_action( 'wp_head', 'afterlight_javascript_detection', 0 );
/**
* Enqueue scripts and styles.
*
* @since Afterlight 1.0
*/
function afterlight_scripts() {
// Add custom fonts, used in the main stylesheet.
wp_enqueue_style( 'afterlight-fonts', afterlight_fonts_url(), array(), null );
// Add Genericons, used in the main stylesheet.
wp_enqueue_style( 'genericons', get_template_directory_uri() . '/genericons/genericons.css', array(), '3.3' );
// Load our main stylesheet.
wp_enqueue_style( 'afterlight-style', get_stylesheet_uri() );
wp_enqueue_script( 'afterlight-skip-link-focus-fix', get_template_directory_uri() . '/js/skip-link-focus-fix.js', array(), '20150302', 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( 'afterlight-keyboard-image-navigation', get_template_directory_uri() . '/js/keyboard-image-navigation.js', array( 'jquery' ), '20150302' );
}
wp_enqueue_script( 'afterlight-script', get_template_directory_uri() . '/js/functions.js', array( 'jquery' ), '20150302', true );
wp_localize_script( 'afterlight-script', 'screenReaderText', array(
'expand' => '' . __( 'expand child menu', 'afterlight' ) . '',
'collapse' => '' . __( 'collapse child menu', 'afterlight' ) . '',
) );
wp_localize_script( 'afterlight-script', 'toggleButtonText', array(
'menu' => __( 'Menu', 'afterlight' ),
'widgets' => __( 'Widgets', 'afterlight' ),
'both' => __( 'Menu & Widgets', 'afterlight' ),
) );
}
add_action( 'wp_enqueue_scripts', 'afterlight_scripts' );
/**
* Enqueue Google fonts style to admin screen for custom header display.
*
* @since Afterlight 1.0
*/
function afterlight_admin_fonts() {
wp_enqueue_style( 'afterlight-fonts', afterlight_fonts_url(), array(), null );
}
add_action( 'admin_print_scripts-appearance_page_custom-header', 'afterlight_admin_fonts' );
/**
* Add a `screen-reader-text` class to the search form's submit button.
*
* @since Afterlight 1.0
*
* @param string $html Search form HTML.
* @return string Modified search form HTML.
*/
function afterlight_search_form_modify( $html ) {
return str_replace( 'class="search-submit"', 'class="search-submit screen-reader-text"', $html );
}
add_filter( 'get_search_form', 'afterlight_search_form_modify' );
/**
* Adds custom classes to the array of body classes.
*
* @param array $classes Classes for the body element.
* @return array
*/
function afterlight_body_classes( $classes ) {
if ( is_singular() ) {
$classes[] = 'single';
}
if ( has_nav_menu( 'primary' ) ) {
$classes[] = 'primary-menu';
}
if ( ! is_active_sidebar( 'sidebar-1' ) ) {
$classes[] = 'no-widgets';
}
if ( ! is_active_sidebar( 'sidebar-1' ) && ! has_nav_menu( 'primary' ) && ! has_nav_menu( 'social' ) ) {
$classes[] = 'no-sidebar';
}
if ( get_background_image() && '1' == get_theme_mod( 'afterlight_full_page_background', '1' ) ) {
$classes[] = 'full-page-background';
}
if ( '1' == get_theme_mod( 'afterlight_background_overlay', '1' ) ) {
$classes[] = 'has-overlay';
}
return $classes;
}
add_filter( 'body_class', 'afterlight_body_classes' );
/**
* Apply full-page background image to the pseudo element so that it also works on mobile Safari.
*
* @since Afterlight 1.0
*
* @see wp_add_inline_style()
*/
function afterlight_full_page_background_image() {
$image = get_background_image();
$full_page_background = get_theme_mod( 'afterlight_full_page_background', '1' );
$css = '';
if ( ! empty ( $image ) && '1' == $full_page_background ) {
$css .= 'body:before { background-image: url("' . esc_url( $image ) . '"); }';
}
wp_add_inline_style( 'afterlight-style', $css );
}
add_action( 'wp_enqueue_scripts', 'afterlight_full_page_background_image' );
/**
* Implement the Custom Header feature.
*/
require get_template_directory() . '/inc/custom-header.php';
/**
* Custom template tags for this theme.
*/
require get_template_directory() . '/inc/template-tags.php';
/**
* Customizer additions.
*/
require get_template_directory() . '/inc/customizer.php';
/**
* Load Jetpack compatibility file.
*/
require get_template_directory() . '/inc/jetpack.php';