* add_action( 'after_setup_theme', 'my_child_theme_setup' );
* function my_child_theme_setup() {
* // We are providing our own filter for excerpt_length (or using the unfiltered value)
* remove_filter( 'excerpt_length', 'catchbox_excerpt_length' );
* ...
* }
*
*
* For more information on hooks, actions, and filters, see http://codex.wordpress.org/Plugin_API.
*
* @package Catch Themes
* @subpackage Catch Box
* @since Catch Box 1.0
*/
if ( ! function_exists( 'catchbox_content_width' ) ) :
/**
* Change the content width based on the Theme Settings and Page/Post Settings
*/
function catchbox_content_width() {
$layout = catchbox_get_theme_layout();
$content_width = 530;
if ( is_page_template( 'page-fullwidth.php' ) ) {
$content_width = 880; /* pixels */
}
else if ( is_page_template( 'page-disable-sidebar.php' ) ) {
$content_width = 660; /* pixels */
}
else if ( $layout == 'content-onecolumn' || is_page_template( 'page-onecolumn.php' ) ) {
$content_width = 620; /* pixels */
}
}
endif; // catchbox_content_width
add_action( 'after_setup_theme', 'catchbox_content_width', 0 );
/**
* Tell WordPress to run catchbox_setup() when the 'after_setup_theme' hook is run.
*/
add_action( 'after_setup_theme', 'catchbox_setup' );
if ( ! function_exists( 'catchbox_setup' ) ) :
/**
* Sets up theme defaults and registers support for various WordPress features.
*
* Note that this function is hooked into the after_setup_theme hook, which runs
* before the init hook. The init hook is too late for some features, such as indicating
* support post thumbnails.
*
* To override catchbox_setup() in a child theme, add your own catchbox_setup to your child theme's
* functions.php file.
*
* @uses load_theme_textdomain() For translation/localization support.
* @uses add_editor_style() To style the visual editor.
* @uses add_theme_support() To add support for post thumbnails, automatic feed links,custom headers and backgrounds.
* @uses register_nav_menus() To add support for navigation menus.
* @uses register_default_headers() To register the default custom header images provided with the theme.
* @uses set_post_thumbnail_size() To set a custom post thumbnail size.
*
* @since Catch Box 1.0
*/
function catchbox_setup() {
/*
* Make theme available for translation.
* Translations can be filed in the /languages/ directory.
* If you're building a theme based on Catch Box, use a find and replace
* to change 'twentysixteen' to the name of your theme in all the template files
*/
load_theme_textdomain( 'catch-box', get_template_directory() . '/languages' );
// Add default posts and comments RSS feed links to head.
add_theme_support( 'automatic-feed-links' );
/*
* Let WordPress manage the document title.
* By adding theme support, we declare that this theme does not use a
* hard-coded
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' );
//featued posts
add_image_size( 'featured-slider-larger', 980, 400, true );
add_image_size( 'featured-slider', 640, 318, true ); // Used for featured posts if a large-feature doesn't exist
// Add support for custom backgrounds
add_theme_support( 'custom-background' );
// This theme uses wp_nav_menu() in three locations.
register_nav_menus(array(
'primary' => __( 'Primary Menu', 'catch-box' ),
'secondary' => __( 'Secondary Menu', 'catch-box' ),
'footer' => __( 'Footer Menu', 'catch-box' )
) );
/*
* 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',
) );
/*
* This theme styles the visual editor to resemble the theme style,
* specifically font, colors, icons, and column width.
*/
add_editor_style();
/**
* This feature enables Jetpack plugin Infinite Scroll
*/
add_theme_support( 'infinite-scroll', array(
'type' => 'click',
'container' => 'content',
'footer_widgets' => array( 'sidebar-2', 'sidebar-3', 'sidebar-4' ),
'footer' => 'page',
) );
//@remove Remove check when WordPress 4.8 is released
if ( function_exists( 'has_custom_logo' ) ) {
/**
* Setup Custom Logo Support for theme
* Supported from WordPress version 4.5 onwards
* More Info: https://make.wordpress.org/core/2016/03/10/custom-logo/
*/
add_theme_support( 'custom-logo',
array(
'height' => 125,
'width' => 300,
'flex-height' => true,
'flex-width' => true,
)
);
}
}
endif; // catchbox_setup
if ( ! function_exists( 'catchbox_get_theme_layout' ) ) :
/**
* Returns Theme Layout prioritizing the meta box layouts
*
* @uses get_options
*
* @action wp_head
*
* @since Catch Box 4.6
*/
function catchbox_get_theme_layout() {
$id = '';
global $post, $wp_query;
// Front page displays in Reading Settings
$page_on_front = get_option('page_on_front') ;
$page_for_posts = get_option('page_for_posts');
// Get Page ID outside Loop
$page_id = $wp_query->get_queried_object_id();
// Blog Page or Front Page setting in Reading Settings
if ( $page_id == $page_for_posts || $page_id == $page_on_front ) {
$id = $page_id;
}
else if ( is_singular() ) {
if ( is_attachment() ) {
$id = $post->post_parent;
}
else {
$id = $post->ID;
}
}
//Get appropriate metabox value of layout
if ( '' != $id ) {
$layout = get_post_meta( $id, 'catchbox-sidebarlayout', true );
}
else {
$layout = 'default';
}
//Load options data
$options = catchbox_get_theme_options();
//check empty and load default
if ( empty( $layout ) || 'default' == $layout ) {
$layout = $options['theme_layout'];
}
//Condition checks for backward compatibility
if ( 'content-sidebar' ==$layout ) {
$layout = 'right-sidebar';
}
else if ( 'sidebar-content' ==$layout ) {
$layout = 'left-sidebar';
}
else if ( 'content-onecolumn' ==$layout ) {
$layout = 'no-sidebar-one-column';
}
return $layout;
}
endif; //catchbox_get_theme_layout
/**
* Migrate Logo to New WordPress core Custom Logo
*
*
* Runs if version number saved in theme_mod "logo_version" doesn't match current theme version.
*/
function catchbox_logo_migrate() {
$ver = get_theme_mod( 'logo_version', false );
// Return if update has already been run
if ( version_compare( $ver, '3.6' ) >= 0 ) {
return;
}
// If a logo has been set previously, update to use logo feature introduced in WordPress 4.5
if ( function_exists( 'the_custom_logo' ) ) {
$header_image = get_header_image();
if ( ! empty( $header_image ) ) {
// Since previous logo was stored a URL, convert it to an attachment ID
$logo = attachment_url_to_postid( $header_image );
if ( is_int( $logo ) ) {
set_theme_mod( 'custom_logo', $logo );
}
}
//Remove header image previously set as logo
set_theme_mod( 'header_image', '' );
set_theme_mod( 'header_image_data', array() );
// Update to match logo_version so that script is not executed continously
set_theme_mod( 'logo_version', '3.6' );
}
}
add_action( 'after_setup_theme', 'catchbox_logo_migrate' );
/**
* Migrate Custom Favicon to WordPress core Site Icon
*
* Runs if version number saved in theme_mod "site_icon_version" doesn't match current theme version.
*/
function catchbox_site_icon_migrate() {
$ver = get_theme_mod( 'site_icon_version', false );
//Return if update has already been run
if ( version_compare( $ver, '3.6' ) >= 0 ) {
return;
}
/**
* Get Theme Options Values
*/
$options = catchbox_get_theme_options();
// If a logo has been set previously, update to use logo feature introduced in WordPress 4.5
if ( function_exists( 'has_site_icon' ) ) {
if( isset( $options['fav_icon'] ) && '' != $options['fav_icon'] ) {
// Since previous logo was stored a URL, convert it to an attachment ID
$site_icon = attachment_url_to_postid( $options['fav_icon'] );
if ( is_int( $site_icon ) ) {
update_option( 'site_icon', $site_icon );
}
}
// Update to match site_icon_version so that script is not executed continously
set_theme_mod( 'site_icon_version', '3.6' );
}
}
add_action( 'after_setup_theme', 'catchbox_site_icon_migrate' );
/**
* Sets the post excerpt length.
*
* To override this length in a child theme, remove the filter and add your own
* function tied to the excerpt_length filter hook.
*/
function catchbox_excerpt_length( $length ) {
$options = catchbox_get_theme_options();
if( empty( $options['excerpt_length'] ) )
$options = catchbox_get_default_theme_options();
$length = $options['excerpt_length'];
return $length;
}
add_filter( 'excerpt_length', 'catchbox_excerpt_length' );
if ( ! function_exists( 'catchbox_continue_reading_link' ) ) :
/**
* Returns a "Continue Reading" link for excerpts
*/
function catchbox_continue_reading_link() {
return ' ' . sprintf(
__( 'Continue reading %s', 'catch-box' ),
' '.get_the_title().''
).
'→';
}
endif;
/**
* Replaces "[...]" (appended to automatically generated excerpts) with an ellipsis and catchbox_continue_reading_link().
*
* To override this in a child theme, remove the filter and add your own
* function tied to the excerpt_more filter hook.
*/
function catchbox_auto_excerpt_more( $more ) {
return catchbox_continue_reading_link();
}
add_filter( 'excerpt_more', 'catchbox_auto_excerpt_more' );
/**
* Adds a pretty "Continue Reading" link to custom post excerpts.
*
* To override this link in a child theme, remove the filter and add your own
* function tied to the get_the_excerpt filter hook.
*/
function catchbox_custom_excerpt_more( $output ) {
if ( has_excerpt() && ! is_attachment() ) {
$output .= catchbox_continue_reading_link();
}
return $output;
}
add_filter( 'get_the_excerpt', 'catchbox_custom_excerpt_more' );
if ( ! function_exists( 'catchbox_content_nav' ) ) :
/**
* Display navigation to next/previous pages when applicable
*/
function catchbox_content_nav( $nav_id ) {
global $wp_query;
/**
* Check Jetpack Infinite Scroll
* if it's active then disable pagination
*/
if ( class_exists( 'Jetpack', false ) ) {
$jetpack_active_modules = get_option('jetpack_active_modules');
if ( $jetpack_active_modules && in_array( 'infinite-scroll', $jetpack_active_modules ) ) {
return false;
}
}
if ( $wp_query->max_num_pages > 1 ) { ?>
max_num_pages > 1 ) { ?>
]*?href=[\'"](.+?)[\'"]/is', get_the_content(), $matches ) )
return false;
return esc_url_raw( $matches[1] );
}
if ( ! function_exists( 'catchbox_footer_sidebar_class' ) ):
/**
* Count the number of footer sidebars to enable dynamic classes for the footer
*/
function catchbox_footer_sidebar_class() {
$count = 0;
if ( is_active_sidebar( 'sidebar-2' ) )
$count++;
if ( is_active_sidebar( 'sidebar-3' ) )
$count++;
if ( is_active_sidebar( 'sidebar-4' ) )
$count++;
$class = '';
switch ( $count ) {
case '1':
$class = 'one';
break;
case '2':
$class = 'two';
break;
case '3':
$class = 'three';
break;
}
if ( $class )
echo 'class="' . $class . '"';
}
endif; // catchbox_footer_sidebar_class
if ( ! function_exists( 'catchbox_comment' ) ) :
/**
* Template for comments and pingbacks.
*
* To override this walker in a child theme without modifying the comments template
* simply create your own catchbox_comment(), and that function will be used instead.
*
* Used as a callback by wp_list_comments() for displaying the comments.
*
* @since Catch Box 1.0
*/
function catchbox_comment( $comment, $args, $depth ) {
$GLOBALS['comment'] = $comment;
switch ( $comment->comment_type ) :
case 'pingback' :
case 'trackback' :
?>