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 https://developer.wordpress.org/themes/functionality/featured-images-post-thumbnails/
*/
add_theme_support( 'post-thumbnails' );
/*
* Add various custom image sizes.
*
* @link https://developer.wordpress.org/themes/functionality/featured-images-post-thumbnails/
*/
add_image_size( 'post-full', 1200, 9999 );
add_image_size( 'post-landscape', 800, 600, true );
// This theme uses wp_nav_menu() in one location.
register_nav_menus( array(
'primary' => esc_html__( 'Primary Menu', 'brand' ),
) );
/*
* 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://developer.wordpress.org/themes/functionality/post-formats/
*/
add_theme_support( 'post-formats', array(
'audio',
'gallery',
'video',
'quote',
'link',
) );
// Adds support for custom background feature.
add_theme_support( 'custom-background' );
// Adds support for selective refresh in the Customizer.
add_theme_support( 'customize-selective-refresh-widgets' );
}
endif;
add_action( 'after_setup_theme', 'brand_setup' );
/**
* Set default options
*/
function brand_get_defaults()
{
$brand_defaults = array(
'container_width' => '1180',
'nav_width' => 'fullwidth',
'sticky_menu' => 'no',
'logo_position' => 'inside_header',
'show_site_title' => '1',
'logo' => 0,
'logo_mobile' => 0,
'nav_position' => 'inside_above',
'nav_search' => 'enabled',
'nav_alignment' => 'left',
'nav_orientation' => 'horizontal',
'logo_alignment' => 'left',
'header_width' => 'fullwidth',
'header_alignment' => 'center',
'page_title_width' => 'fullwidth',
'page_title_alignment' => 'left',
'site_title_mobile_spacing_top' => '0',
'site_title_mobile_spacing_bottom' => '0',
'body_bg_color' => '#eeeeee',
'body_text_color' => '#777777',
'link_color' => '#222222',
'link_hover_color' => '#1ebaf3',
'sidebar_layout' => 'no',
'content_layout' => 'separated_blocks',
'featured_position' => 'inside',
'footer_widgets' => '0',
'footer_widgets_width' => 'fullwidth',
'footer_width' => 'fullwidth',
'show_excerpt' => 'yes',
'show_thumb_index' => 'yes',
'show_thumb_single' => 'yes',
'excerpt_length' => '20',
'post_image_no_padding' => false,
'woocommerce_products_cols' => 3,
);
return apply_filters( 'brand_option_defaults', $brand_defaults );
}
/**
* 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 brand_content_width() {
$GLOBALS['content_width'] = apply_filters( 'brand_content_width', 1180 );
}
add_action( 'after_setup_theme', 'brand_content_width', 0 );
/**
* Register widget area.
*
* @link https://developer.wordpress.org/themes/functionality/sidebars/#registering-a-sidebar
*/
function brand_widgets_init() {
register_sidebar( array(
'name' => esc_html__( 'Sidebar', 'brand' ),
'id' => 'sidebar-1',
'description' => 'Standard sidebar',
'before_widget' => '',
'before_title' => '
',
) );
register_sidebar( array(
'name' => esc_html__( 'Footer Sidebar Column 1', 'brand' ),
'id' => 'sidebar-footer-1',
'description' => esc_html__( 'Footer sidebar column 1', 'brand' ),
'before_widget' => '',
'before_title' => '',
) );
register_sidebar( array(
'name' => esc_html__( 'Footer Sidebar Column 2', 'brand' ),
'id' => 'sidebar-footer-2',
'description' => esc_html__( 'Footer sidebar column 2', 'brand' ),
'before_widget' => '',
'before_title' => '',
) );
register_sidebar( array(
'name' => esc_html__( 'Footer Sidebar Column 3', 'brand' ),
'id' => 'sidebar-footer-3',
'description' => esc_html__( 'Footer sidebar column 3', 'brand' ),
'before_widget' => '',
'before_title' => '',
) );
register_sidebar( array(
'name' => esc_html__( 'Footer Sidebar Column 4', 'brand' ),
'id' => 'sidebar-footer-4',
'description' => esc_html__( 'Footer sidebar column 4', 'brand' ),
'before_widget' => '',
'before_title' => '',
) );
}
add_action( 'widgets_init', 'brand_widgets_init' );
/**
* Add Woocommerce support and fit it to Brand Theme.
*/
require get_template_directory() . '/inc/woocommerce.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';
/**
* Build navigation.
*/
require get_template_directory() . '/inc/navigation.php';
/**
* Customizer additions.
*/
require get_template_directory() . '/inc/customizer.php';
/**
* Load add-ons options.
*/
require get_template_directory() . '/inc/advanced/add-ons.php';
/**
* Implement the Custom Header feature.
*/
require get_template_directory() . '/inc/custom-header.php';
/**
* Custom classes.
*/
require get_template_directory() . '/inc/brand-classes.php';
/**
* Options page.
*/
require get_template_directory() . '/inc/options/brand-options.php';
/**
* Enqueue scripts and styles.
*/
function brand_scripts() {
wp_enqueue_style( 'brand-style', get_stylesheet_uri(), BRAND_VER );
// Loads FontAwesome stylesheet
wp_enqueue_style('fontawesome-style', get_template_directory_uri() . '/assets/font-awesome/css/font-awesome.min.css', FONTAWESOME_VER);
// Loads Google Fonts
wp_enqueue_style('google-fonts', 'https://fonts.googleapis.com/css?family=Raleway:400,700');
if( !wp_style_is( 'brand-bootstrap' )) {
wp_register_style(
'brand-bootstrap',
get_template_directory_uri() . '/assets/css/bootstrap.min.css',
array(),
BOOTSTRAP_VER,
'all'
);
wp_enqueue_style('brand-bootstrap');
}
wp_enqueue_style('brand', get_template_directory_uri() . '/assets/css/brand.min.css', array('brand-bootstrap'), BRAND_VER );
if( !wp_script_is( 'brand-bootstrap' )) {
wp_register_script(
'brand-bootstrap',
get_template_directory_uri() . '/assets/javascripts/bootstrap.min.js',
array('jquery'),
BOOTSTRAP_VER,
true
);
wp_enqueue_script( 'brand-bootstrap' );
}
wp_enqueue_script( 'brand', get_template_directory_uri() . '/assets/javascripts/brand.min.js', array(), BRAND_VER, true );
if ( is_singular() && comments_open() && get_option( 'thread_comments' ) ) {
wp_enqueue_script( 'comment-reply' );
}
wp_register_script( 'brand-video', get_template_directory_uri() . '/assets/javascripts/brand-video.js', array( 'jquery' ), BRAND_VER, true );
global $post;
if( ( isset( $post->ID ) && has_post_format( 'video', $post->ID ) ) || is_home() ) {
wp_enqueue_script( 'brand-video' );
}
}
add_action( 'wp_enqueue_scripts', 'brand_scripts' );
// Enqueque script and style for admin
function brand_admin_scripts($hook) {
if( 'post.php' == $hook || 'post-new.php' == $hook ) {
//Enqueque script for upload custom image
wp_enqueue_script( 'brand-img-uploader',
get_template_directory_uri() . '/assets/javascripts/admin/img-uploader.js',
array('jquery')
);
wp_localize_script( 'brand-img-uploader', 'brand_img_uploader_obj', array(
'ajax_url' => admin_url( 'admin-ajax.php' ),
'media_frame_title' => __('Select or Upload Image', 'brand'),
'media_frame_btn' => __('Use this image', 'brand'),
));
//Includes WordPress color picker in post and page
wp_enqueue_style( 'wp-color-picker' );
wp_enqueue_script( 'maxsdesign-color-picker', get_template_directory_uri() . '/assets/javascripts/admin/maxsdesign-color-picker.js', array('wp-color-picker'), BRAND_VER, true );
// Enqueque styles for post and page metaboxes
wp_enqueue_style('maxsdesign-metaboxes-style', get_template_directory_uri() . '/assets/css/admin/maxsdesign-metaboxes.css', array(), BRAND_VER);
}
// Enqueue options page styles
if( 'appearance_page_brand_setting_page' == $hook ) {
wp_enqueue_style('brand-options-styles', get_template_directory_uri() . '/assets/css/admin/brand-option-admin.css', array(), BRAND_VER);
}
}
add_action('admin_enqueue_scripts', 'brand_admin_scripts');
/**
* Adds metaboxes.
*/
require get_template_directory() . '/inc/metaboxes/metaboxes.php';
/**
* Loads Jetpack compatibility file.
*/
require get_template_directory() . '/inc/jetpack.php';
/**
* Filter the excerpt length to 20 characters.
*
* @param int $length Excerpt length.
* @return int (Maybe) modified excerpt length.
*/
function brand_custom_excerpt_length( $length ) {
$brand_settings = wp_parse_args(
get_option( 'brand_settings', array() ),
brand_get_defaults()
);
return $brand_settings['excerpt_length'];
}
add_filter( 'excerpt_length', 'brand_custom_excerpt_length', 999 );
if (!function_exists('wp_get_attachment_image_url')) {
/**
* Add wp_get_attachment_image_url function in WordPress version 4.3
*
* @param int $attachment_id Image attachment ID.
* @param string|array $size Optional. Image size to retrieve. Accepts any valid image size, or an array
* of width and height values in pixels (in that order). Default 'thumbnail'.
* @param bool $icon Optional. Whether the image should be treated as an icon. Default false.
* @return string|false Attachment URL or false if no image is available.
*/
function wp_get_attachment_image_url( $attachment_id, $size = 'thumbnail', $icon = false ) {
$image = wp_get_attachment_image_src( $attachment_id, $size, $icon );
return isset( $image['0'] ) ? $image['0'] : false;
}
}
/**
* Converts a HEX value to RGB.
*
* @since Brand 1.0
*
* @param string $color The original color, in 3- or 6-digit hexadecimal form.
* @return array Array containing RGB (red, green, and blue) values for the given
* HEX code, empty array otherwise.
*/
function brand_hex2rgb( $color ) {
$color = trim( $color, '#' );
if ( strlen( $color ) === 3 ) {
$r = hexdec( substr( $color, 0, 1 ).substr( $color, 0, 1 ) );
$g = hexdec( substr( $color, 1, 1 ).substr( $color, 1, 1 ) );
$b = hexdec( substr( $color, 2, 1 ).substr( $color, 2, 1 ) );
} else if ( strlen( $color ) === 6 ) {
$r = hexdec( substr( $color, 0, 2 ) );
$g = hexdec( substr( $color, 2, 2 ) );
$b = hexdec( substr( $color, 4, 2 ) );
} else {
return array();
}
return array( 'red' => $r, 'green' => $g, 'blue' => $b );
}
if ( !function_exists('brand_sidebar' ) ) {
/**
* Function that adds classes on body element for show sidebar.
* @param $classes array of current body classes
* @return array array of changed body classes
*/
function brand_sidebar($classes) {
// Get theme options
$brand_settings = wp_parse_args(
get_option( 'brand_settings', array() ),
brand_get_defaults()
);
global $post;
if( is_singular() && !is_attachment() ) {
$brand_show_sidebar = get_post_meta( $post->ID, '_brand_show_sidebar', true );
$classes[] = isset($brand_show_sidebar) && $brand_show_sidebar != '' && $brand_show_sidebar !== 'default' ? $brand_show_sidebar . '-sidebar' : $brand_settings['sidebar_layout'] . '-sidebar';
} else {
$classes[] = $brand_settings['sidebar_layout'] . '-sidebar';
}
return $classes;
}
add_filter('body_class','brand_sidebar');
}
if (!function_exists('brand_logo_above_nav_class')) {
/**
* Function that adds classes on body element if logo is above nav.
* @param $classes array of current body classes
* @return array array of changed body classes
*/
function brand_logo_above_nav_class($classes) {
$classes[] = '';
// Get theme options
$brand_settings = wp_parse_args(
get_option( 'brand_settings', array() ),
brand_get_defaults()
);
if($brand_settings['logo_position'] === 'no_logo') {
$classes[] = 'no-logo';
} else if($brand_settings['logo_position'] === 'inline') {
$classes[] = 'logo-in-nav';
} else {
$classes[] = 'logo-inside-header';
}
return $classes;
}
add_filter('body_class','brand_logo_above_nav_class');
}
/**
* Adds custom classes to the body if navigation is inside header
* @since 1.0
*/
add_filter( 'body_class', 'brand_nav_inside_header_below');
function brand_nav_inside_header_below( $classes='' )
{
// Get theme options
$brand_settings = wp_parse_args(
get_option( 'brand_settings', array() ),
brand_get_defaults()
);
$nav_position = $brand_settings['nav_position'];
if ( $nav_position === 'inside_below' || $nav_position === 'inside_above' ) :
$classes[] = 'nav-inside';
endif;
return $classes;
}
/**
* Adds custom classes to the body according to content layout setting.
* @since 1.0
*/
add_filter( 'body_class', 'brand_content_layout_class');
function brand_content_layout_class( $classes='' )
{
// Get theme options
$brand_settings = wp_parse_args(
get_option( 'brand_settings', array() ),
brand_get_defaults()
);
$content_layout = $brand_settings['content_layout'];
if ( $content_layout === 'one_block' ) :
$classes[] = 'one-block';
elseif ( $content_layout === 'separated_blocks' ) :
$classes[] = 'separated-blocks';
endif;
return $classes;
}
add_filter( 'body_class', 'brand_float_nav_class');
function brand_float_nav_class( $classes='' )
{
// Get theme options
$brand_settings = wp_parse_args(
get_option( 'brand_settings', array() ),
brand_get_defaults()
);
if ( $brand_settings['nav_position'] === 'float_right' ) :
$classes[] = 'float-right-nav';
elseif ( $brand_settings['nav_position'] === 'float_left' ) :
$classes[] = 'float-left-nav';
endif;
return $classes;
}
/**
* Adds custom classes to the body if display_header_text return true.
* @since 1.2.0
*/
add_filter( 'body_class', 'brand_show_site_title_class');
function brand_show_site_title_class( $classes='' ) {
$brand_settings = wp_parse_args(
get_option( 'brand_settings', array() ),
brand_get_defaults()
);
if ( $brand_settings['show_site_title'] === '1' ) :
$classes[] = 'show-site-title';
endif;
return $classes;
}
/**
* Adds custom classes to the body according to navigation orientation setting.
* @since 1.2.0
*/
add_filter( 'body_class', 'brand_nav_orientation_class');
function brand_nav_orientation_class( $classes='' ) {
// Get theme options
$brand_settings = wp_parse_args(
get_option( 'brand_settings', array() ),
brand_get_defaults()
);
if ( $brand_settings['nav_orientation'] === 'horizontal' ) :
$classes[] = 'horizontal-main-nav';
else:
$classes[] = 'vertical-main-nav';
endif;
return $classes;
}
/**
* Adds custom classes to the body if is set a header image.
* @since 1.6.0
*/
add_filter( 'body_class', 'brand_has_custom_header_img_class');
function brand_has_custom_header_img_class( $classes='' ) {
if( is_singular() ) {
global $post;
$brand_backgrounds_meta = get_post_meta( $post->ID, '_brand_backgrounds_meta', true );
$bg_header_use_general = isset( $brand_backgrounds_meta['bg_header_use_general'] ) ? $brand_backgrounds_meta['bg_header_use_general'] : 'yes';
$header_image_id = isset( $brand_backgrounds_meta['custom_header_image_id'] ) ? $brand_backgrounds_meta['custom_header_image_id'] : 0;
if( $bg_header_use_general === 'yes' && has_header_image() ) {
$classes[] = 'brand-has-header-image';
} else if( $bg_header_use_general === 'no' && $header_image_id !== 0 ) {
$classes[] = 'brand-has-header-image';
}
} else if( get_header_image() !== '' && get_header_image() !== false) {
$classes[] = 'brand-has-header-image';
}
return $classes;
}
/**
* Add footer site info.
* @since 1.6
*/
if ( ! brand_addons_installed() ) {
function brand_print_site_info() { ?>
Proudly powered by WordPress
|
Theme: brand by Massimo Sanfelice - Maxsdesign