tag in the document head, and expect WordPress to
* provide it for us.
*/
add_theme_support( 'title-tag' );
add_theme_support( 'customize-selective-refresh-widgets' );
/*
* 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( 740, 430, true );
add_image_size( 'independent-publisher-2-banner', 1440, 600, true );
add_image_size( 'independent-publisher-2-full-width', 1100, 9999 );
// This theme uses wp_nav_menu() in one location.
register_nav_menus(
array(
'menu-1' => esc_html__( 'Header', 'independent-publisher-2' ),
)
);
/**
* Add custom logo support
*/
add_theme_support(
'custom-logo',
array(
'height' => 300,
'width' => 1500,
'flex-width' => true,
)
);
/*
* 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(
'independent_publisher_2_custom_background_args',
array(
'default-color' => 'ffffff',
)
)
);
// Load regular editor styles into the new block-based editor.
add_theme_support( 'editor-styles' );
// Add support for Block Styles.
add_theme_support( 'wp-block-styles' );
// Add support for responsive embeds.
add_theme_support( 'responsive-embeds' );
// Add support for full and wide align images.
add_theme_support( 'align-wide' );
// Add support for custom line height controls.
add_theme_support( 'custom-line-height' );
// Add support for experimental cover block spacing.
add_theme_support( 'custom-spacing' );
// Add support for custom color scheme.
add_theme_support(
'editor-color-palette',
array(
array(
'name' => __( 'Medium Blue', 'independent-publisher-2' ),
'slug' => 'medium-blue',
'color' => '#0087be',
),
array(
'name' => __( 'Bright Blue', 'independent-publisher-2' ),
'slug' => 'bright-blue',
'color' => '#00aadc',
),
array(
'name' => __( 'Dark Gray', 'independent-publisher-2' ),
'slug' => 'dark-gray',
'color' => '#4d4d4b',
),
array(
'name' => __( 'Light Gray', 'independent-publisher-2' ),
'slug' => 'light-gray',
'color' => '#b3b3b1',
),
array(
'name' => __( 'White', 'independent-publisher-2' ),
'slug' => 'white',
'color' => '#fff',
),
)
);
}
endif; // independent_publisher_2_setup
add_action( 'after_setup_theme', 'independent_publisher_2_setup' );
if ( ! function_exists( 'independent_publisher_2_word_count' ) ) :
/**
* Gets the number of words in the post content.
*
* @link http://php.net/str_word_count
* @link http://php.net/number_format
*/
function independent_publisher_2_word_count() {
$content = get_post_field( 'post_content', get_the_ID() );
$count = str_word_count( strip_tags( $content ) );
$time = $count / 250; //Roughly 250 wpm reading time
// if time less than 1 explicitly set to 1.
if ( $time < 1 ) {
$time = 1;
}
return number_format( $time );
}
endif; // independent_publisher_2_word_count
/**
* Set the content width in pixels, based on the theme's design and stylesheet.
*
* Priority 0 to make it available to lower priority callbacks.
*
* @global int $content_width
*/
function independent_publisher_2_content_width() {
$GLOBALS['content_width'] = apply_filters( 'independent_publisher_2_content_width', 1100 );
}
add_action( 'after_setup_theme', 'independent_publisher_2_content_width', 0 );
/**
* Register widget area.
*
* @link http://codex.wordpress.org/Function_Reference/register_sidebar
*/
function independent_publisher_2_widgets_init() {
register_sidebar(
array(
'name' => esc_html__( 'Sidebar', 'independent-publisher-2' ),
'id' => 'sidebar-1',
'description' => '',
'before_widget' => '',
'before_title' => '
',
)
);
register_sidebar(
array(
'name' => esc_html__( 'Footer 1', 'independent-publisher-2' ),
'id' => 'sidebar-2',
'description' => '',
'before_widget' => '',
'before_title' => '',
)
);
register_sidebar(
array(
'name' => esc_html__( 'Footer 2', 'independent-publisher-2' ),
'id' => 'sidebar-3',
'description' => '',
'before_widget' => '',
'before_title' => '',
)
);
register_sidebar(
array(
'name' => esc_html__( 'Footer 3', 'independent-publisher-2' ),
'id' => 'sidebar-4',
'description' => '',
'before_widget' => '',
'before_title' => '',
)
);
}
add_action( 'widgets_init', 'independent_publisher_2_widgets_init' );
/**
* Enqueue scripts and styles.
*/
function independent_publisher_2_scripts() {
// Add Genericons, used in the main stylesheet.
wp_enqueue_style( 'genericons', get_template_directory_uri() . '/genericons/genericons.css', array(), '3.3.1' );
wp_enqueue_style( 'independent-publisher-2-style', get_stylesheet_uri() );
// Theme block stylesheet.
wp_enqueue_style( 'independent-publisher-2-block-style', get_theme_file_uri( '/css/blocks.css' ), array( 'independent-publisher-2-style' ), '1.0' );
wp_enqueue_script( 'independent-publisher-2-navigation', get_template_directory_uri() . '/js/navigation.js', array(), '20170317', true );
if ( ! is_active_sidebar( 'sidebar-1' ) ) {
wp_enqueue_script( 'independent-publisher-2-images', get_template_directory_uri() . '/js/independent-publisher-2.js', array(), '20260702', true );
}
// If there's an active Video widget, and it's (hopefully) in the footer widget area
if ( is_active_widget( '', '', 'media_video' ) && ( is_active_sidebar( 'sidebar-2' ) || is_active_sidebar( 'sidebar-3' ) || is_active_sidebar( 'sidebar-4' ) ) ) {
wp_enqueue_script( 'independent-publisher-2-video-widget', get_template_directory_uri() . '/js/video-widget.js', array(), '20210111', true );
}
wp_enqueue_script( 'independent-publisher-2-skip-link-focus-fix', get_template_directory_uri() . '/js/skip-link-focus-fix.js', array(), '20170315', true );
if ( is_singular() ) {
if ( comments_open() && get_option( 'thread_comments' ) ) {
wp_enqueue_script( 'comment-reply' );
}
}
independent_publisher_2_maybe_add_hero_image_as_bg();
}
add_action( 'wp_enqueue_scripts', 'independent_publisher_2_scripts' );
/**
* Enqueue editor styles for Gutenberg
*/
function independent_publisher_2_block_editor_styles() {
// Block styles.
wp_enqueue_style( 'independent-pub-block-editor-style', get_theme_file_uri( '/css/editor-blocks.css' ) );
}
add_action( 'enqueue_block_editor_assets', 'independent_publisher_2_block_editor_styles' );
/**
* Add a hero image as an
tag, if appropriate.
* Used by the `header.php` template.
*/
function independent_publisher_2_maybe_add_hero_image_as_img_tag() {
if ( ! independent_publisher_2_should_use_img_tag_for_hero() ) {
return;
}
$attr = array(
'class' => 'hero-header-image',
'loading' => 'eager',
'fetchpriority' => 'high'
);
if ( independent_publisher_2_should_add_cover_image() ) {
// Use cover image if we meet the criteria.
the_post_thumbnail( 'full', $attr );
} elseif ( independent_publisher_2_has_header_image() ) {
// A custom header image is set.
the_header_image_tag( $attr );
}
}
/**
* Add a hero image as a background image style, if appropriate.
* Used by `independent_publisher_2_scripts()` when enqueuing scripts and styles.
*/
function independent_publisher_2_maybe_add_hero_image_as_bg() {
if ( independent_publisher_2_should_use_img_tag_for_hero() ) {
return;
}
if ( independent_publisher_2_should_add_cover_image() ) {
// Use cover image if we meet the criteria.
$banner = get_the_post_thumbnail_url( get_the_ID(), 'independent-publisher-2-banner' );
wp_add_inline_style(
'independent-publisher-2-style',
independent_publisher_2_get_hero_image_css( $banner )
);
} elseif ( independent_publisher_2_has_header_image() ) {
// A custom header image is set.
wp_add_inline_style(
'independent-publisher-2-style',
independent_publisher_2_get_hero_image_css( get_header_image() )
);
}
}
/**
* Returns true if an
tag should be used to render the hero image (if it exists).
* If false, it means a background image style should be used instead.
*
* @return bool
*/
function independent_publisher_2_should_use_img_tag_for_hero() {
// Cache result, to avoid running more than once.
static $use_img_tag = null;
if ( null !== $use_img_tag ) {
return $use_img_tag;
}
// Default to true.
$use_img_tag = true;
$css = (string) wp_get_custom_css();
// WordPress.com and older Jetpack store custom CSS in a 'safecss'
// post that wp_get_custom_css() doesn't read.
if ( class_exists( 'Jetpack_Custom_CSS' ) ) {
if ( is_callable( array( 'Jetpack_Custom_CSS', 'get_css' ) ) ) {
$css .= "\n" . Jetpack_Custom_CSS::get_css();
}
if ( is_callable( array( 'Jetpack_Custom_CSS', 'skip_stylesheet' ) ) && Jetpack_Custom_CSS::skip_stylesheet() ) {
$use_img_tag = false;
}
}
// If `hero-header` or `site-hero-section` appear in the custom CSS, fall back to
// using a background image style, instead of an `
` element.
if ( false !== stripos( $css, 'hero-header' ) || false !== stripos( $css, 'site-hero-section' ) ) {
$use_img_tag = false;
}
return $use_img_tag;
}
/**
* Returns the CSS to be used to add the hero image to the page
* (when using a background image style).
*
* @return string
*/
function independent_publisher_2_get_hero_image_css( $url ) {
return sprintf(
'#hero-header { background: url("%s") no-repeat center; background-size: cover; background-attachment: scroll; }',
esc_url( $url )
);
}
/**
* Returns true if a post Featured Image should be displayed.
*
* @return bool
*/
function independent_publisher_2_should_add_cover_image() {
$is_wc_product_page = false;
if ( class_exists( 'WooCommerce' ) && is_product() ) {
$is_wc_product_page = true;
}
return independent_publisher_2_has_cover_image() &&
independent_publisher_2_jetpack_featured_image_display() &&
! $is_wc_product_page;
}
/**
* Returns true if a post Featured Image can be displayed.
*
* @return bool
*/
function independent_publisher_2_has_cover_image() {
if ( is_singular() && ! post_password_required() && ! is_attachment() && independent_publisher_2_has_post_thumbnail() ) {
return true;
} else {
return false;
}
}
/**
* Returns true if there's a header image set.
*
* @return bool
*/
function independent_publisher_2_has_header_image() {
return (bool) get_header_image();
}
/**
* Returns true if the word count can be displayed in posts.
*
* @return bool
*/
function independent_publisher_2_show_word_count() {
$content = get_post_field( 'post_content', get_the_ID() );
return in_array( get_post_type(), array( 'post' ) ) && ! empty( $content ) && (bool) 1 === (bool) get_theme_mod( 'independent_publisher_2_display_reading_time', 1 );
}
/**
* 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';
/**
* Custom functions that act independently of the theme templates.
*/
require get_template_directory() . '/inc/extras.php';
/**
* Customizer additions.
*/
require get_template_directory() . '/inc/customizer.php';
/**
* Load Jetpack compatibility file.
*/
require get_template_directory() . '/inc/jetpack.php';
/**
* Load WooCommerce compatibility file.
*/
if ( class_exists( 'WooCommerce' ) ) {
require get_template_directory() . '/inc/woocommerce.php';
}