__( 'Primary Menu', 'newzer' ),
'social' => __( 'Social Links Menu', 'newzer' ),
) );
//Switch default core markup for search form, comment form, and comments to output valid HTML5.
add_theme_support( 'html5', array(
'comment-form',
'comment-list',
'gallery',
'caption',
) );
// Enable support for Post Formats.
add_theme_support( 'post-formats', array(
'aside',
'image',
'video',
'quote',
'link',
'gallery',
'audio',
) );
// Add theme support for Custom Logo.
add_theme_support( 'custom-logo', array(
'width' => 250,
'height' => 250,
'flex-width' => true,
) );
// Add theme support for selective refresh for widgets.
add_theme_support( 'customize-selective-refresh-widgets' );
/*
* This theme styles the visual editor to resemble the theme style,
* specifically font, colors, and column width.
*/
add_editor_style( array( 'assets/css/editor-style.css', newzer_fonts_url() ) );
// Add theme support for Custom Background.
$args = array(
'default-color' => '#ffffff',
'default-image' =>''
);
add_theme_support( 'custom-background', $args );
$args = array(
'flex-width' => true,
'width' => 1450,
'flex-height' => true,
'height' => 480,
'default-text-color' => '',
'default-image' => get_template_directory_uri() . '/assets/images/header.jpg',
'wp-head-callback' => 'newzer_header_style',
);
register_default_headers( array(
'default-image' => array(
'url' => '%s/assets/images/header.jpg',
'thumbnail_url' => '%s/assets/images/header.jpg',
'description' => __( 'Default Header Image', 'newzer' ),
),
) );
add_theme_support( 'custom-header', $args );
}
add_action( 'after_setup_theme', 'newzer_setup' );
/**
* Set the content width in pixels, based on the theme's design and stylesheet.
* @global int $content_width
*/
function newzer_content_width() {
$content_width = $GLOBALS['content_width'];
// Get layout.
$page_layout = get_theme_mod( 'page_layout' );
// Check if layout is one column.
if ( 'one-column' === $page_layout ) {
if ( newzer_is_frontpage() ) {
$content_width = 644;
} elseif ( is_page() ) {
$content_width = 740;
}
}
// Check if is single post and there is no sidebar.
if ( is_single() && ! is_active_sidebar( 'sidebar-1' ) ) {
$content_width = 740;
}
/**
* Filter Newzer content width of the theme.
* @param int $content_width Content width in pixels.
*/
$GLOBALS['content_width'] = apply_filters( 'newzer_content_width', $content_width );
}
add_action( 'template_redirect', 'newzer_content_width', 0 );
/**
* Add preconnect for Google Fonts.
* @param array $urls URLs to print for resource hints.
* @param string $relation_type The relation type the URLs are printed.
* @return array $urls URLs to print for resource hints.
*/
function newzer_resource_hints( $urls, $relation_type ) {
if ( wp_style_is( 'newzer-fonts', 'queue' ) && 'preconnect' === $relation_type ) {
$urls[] = array(
'href' => 'https://fonts.gstatic.com',
'crossorigin',
);
}
return $urls;
}
add_filter( 'wp_resource_hints', 'newzer_resource_hints', 10, 2 );
/**
* Register widget areas.
*/
function newzer_widgets_init() {
register_sidebar( array(
'name' => __( 'Blog Sidebar', 'newzer' ),
'id' => 'sidebar-1',
'description' => __( 'Add widgets here to appear in your sidebar on blog posts and archive pages.', 'newzer' ),
'before_widget' => '',
'before_title' => '
',
) );
register_sidebar( array(
'name' => __( 'Homepage Widget Area', 'newzer' ),
'id' => 'sidebar-2',
'description' => __( 'Add widgets here to appear in your home page.', 'newzer' ),
'before_widget' => '',
'before_title' => '',
) );
register_sidebar( array(
'name' => __( 'Header Widget - Advertisement Area', 'newzer' ),
'id' => 'sidebar-3',
'description' => __( 'Add widget(Image) here to appear in your header. Recommand Size: 720x90 ', 'newzer' ),
'before_widget' => '',
'after_widget' => '',
'before_title' => '',
'after_title' => '',
) );
register_sidebar( array(
'name' => __( 'Footer 1', 'newzer' ),
'id' => 'footer-1',
'description' => __( 'Add widgets here to appear in your footer.', 'newzer' ),
'before_widget' => '',
'before_title' => '',
) );
register_sidebar( array(
'name' => __( 'Footer 2', 'newzer' ),
'id' => 'footer-2',
'description' => __( 'Add widgets here to appear in your footer.', 'newzer' ),
'before_widget' => '',
'before_title' => '',
) );
register_sidebar( array(
'name' => __( 'Footer 3', 'newzer' ),
'id' => 'footer-3',
'description' => __( 'Add widgets here to appear in your footer.', 'newzer' ),
'before_widget' => '',
'before_title' => '',
) );
register_sidebar( array(
'name' => __( 'Footer 4', 'newzer' ),
'id' => 'footer-4',
'description' => __( 'Add widgets here to appear in your footer.', 'newzer' ),
'before_widget' => '',
'before_title' => '',
) );
}
add_action( 'widgets_init', 'newzer_widgets_init' );
/**
* Replaces "[...]" (appended to automatically generated excerpts) with ... and
* a 'Continue reading' link.
* @param string $link Link to single post/page.
* @return string 'Continue reading' link prepended with an ellipsis.
*/
function newzer_excerpt_more( $link ) {
if ( is_admin() ) {
return $link;
}
$link = sprintf( '',
esc_url( get_permalink( get_the_ID() ) ),
/* translators: %s: Name of current post */
sprintf( __( 'Read More "%s"', 'newzer' ), get_the_title( get_the_ID() ) )
);
return $link;
}
add_filter( 'excerpt_more', 'newzer_excerpt_more' );
/**
* Handles JavaScript detection.
*
* Adds a `js` class to the root `` element when JavaScript is detected.
*
*/
function newzer_javascript_detection() {
echo "\n";
}
add_action( 'wp_head', 'newzer_javascript_detection', 0 );
/**
* Add a pingback url auto-discovery header for singularly identifiable articles.
*/
function newzer_pingback_header() {
if ( is_singular() && pings_open() ) {
printf( '' . "\n", get_bloginfo( 'pingback_url' ) );
}
}
add_action( 'wp_head', 'newzer_pingback_header' );
/**
* Enqueue scripts and styles.
*/
function newzer_scripts() {
// Theme stylesheet.
wp_enqueue_style( 'newzer-style', get_template_directory_uri() . '/style.css', array(), '1.0' );
if ( is_rtl() ){
wp_enqueue_style( 'bootstrap-rtl', get_template_directory_uri() . '/assets/css/bootstrap-rtl.css');
}
//Bootstrap stylesheet.
wp_enqueue_style( 'bootstrap-style', get_template_directory_uri() . '/assets/css/bootstrap.css' );
//Fontawesome web stylesheet.
wp_enqueue_style( 'fontawesome-style', get_template_directory_uri() . '/assets/css/font-awesome.css' );
//OwlCarousel stylesheet.
wp_enqueue_style( 'owlcarousel-style', get_template_directory_uri() . '/assets/css/owl-carousel.css' );
//Animate
wp_enqueue_style( 'animate-style', get_template_directory_uri() . '/assets/css/animate.css' );
// Load the Internet Explorer 9 specific stylesheet, to fix display issues in the Customizer.
if ( is_customize_preview() ) {
wp_enqueue_style( 'newzer-ie9', get_theme_file_uri( '/assets/css/ie9.css' ), array( 'newzer-style' ), '1.0' );
wp_style_add_data( 'newzer-ie9', 'conditional', 'IE 9' );
}
// Load the Internet Explorer 8 specific stylesheet.
wp_enqueue_style( 'newzer-ie8', get_theme_file_uri( '/assets/css/ie8.css' ), array( 'newzer-style' ), '1.0' );
wp_style_add_data( 'newzer-ie8', 'conditional', 'lt IE 9' );
// Load the html5 shiv.
wp_enqueue_script( 'html5', get_theme_file_uri( '/assets/js/html5.js' ), array(), '3.7.3' );
wp_script_add_data( 'html5', 'conditional', 'lt IE 9' );
wp_enqueue_script( 'newzer-skip-link-focus-fix', get_theme_file_uri( '/assets/js/skip-link-focus-fix.js' ), array(), '1.0', true );
$newzer_l10n = array(
'quote' => newzer_get_svg( array( 'icon' => 'quote-right' ) ),
);
if ( has_nav_menu( 'top' ) ) {
wp_enqueue_script( 'newzer-navigation', get_theme_file_uri( '/assets/js/navigation.js' ), array( 'jquery' ), '1.0', true );
$newzer_l10n['expand'] = __( 'Expand child menu', 'newzer' );
$newzer_l10n['collapse'] = __( 'Collapse child menu', 'newzer' );
$newzer_l10n['icon'] = newzer_get_svg( array( 'icon' => 'angle-down', 'fallback' => true ) );
}
wp_enqueue_script( 'newzer-global', get_theme_file_uri( '/assets/js/global.js' ), array( 'jquery' ), '1.0', true );
wp_enqueue_script( 'jquery-scrollto', get_theme_file_uri( '/assets/js/jquery.scrollTo.js' ), array( 'jquery' ), '2.1.2', true );
wp_enqueue_script( 'owlcarousel-script', get_theme_file_uri( '/assets/js/owl-carousel.js' ), array( 'jquery' ), '1.0', true );
wp_enqueue_script( 'bootstrap-script', get_theme_file_uri( '/assets/js/bootstrap.js' ), array( 'jquery' ), '1.0', true );
wp_enqueue_script( 'masonry' );
wp_enqueue_script( 'newzer-easy-jquery', get_theme_file_uri( '/assets/js/jquery.easing.js' ), array( 'jquery' ), '1.0', true );
wp_enqueue_script( 'newzer-easy-ticker', get_theme_file_uri( '/assets/js/jquery.easy-ticker.js' ), array( 'jquery' ), '1.0', true );
wp_enqueue_script( 'newzer-theme-script', get_theme_file_uri( '/assets/js/theme.js' ), array( 'jquery' ), '1.0', true );
wp_localize_script( 'newzer-skip-link-focus-fix', 'newzerScreenReaderText', $newzer_l10n );
if ( is_singular() && comments_open() && get_option( 'thread_comments' ) ) {
wp_enqueue_script( 'comment-reply' );
}
}
add_action( 'wp_enqueue_scripts', 'newzer_scripts' );
/**
* Add custom image sizes attribute to enhance responsive image functionality
* for content images.
*
* @param string $sizes A source size value for use in a 'sizes' attribute.
* @param array $size Image size. Accepts an array of width and height
* values in pixels (in that order).
* @return string A source size value for use in a content image 'sizes' attribute.
*/
function newzer_content_image_sizes_attr( $sizes, $size ) {
$width = $size[0];
if ( 740 <= $width ) {
$sizes = '(max-width: 706px) 89vw, (max-width: 767px) 82vw, 740px';
}
if ( is_active_sidebar( 'sidebar-1' ) || is_archive() || is_search() || is_home() || is_page() ) {
if ( ! ( is_page() && 'one-column' === get_theme_mod( 'page_options' ) ) && 767 <= $width ) {
$sizes = '(max-width: 767px) 89vw, (max-width: 1000px) 54vw, (max-width: 1071px) 543px, 580px';
}
}
return $sizes;
}
add_filter( 'wp_calculate_image_sizes', 'newzer_content_image_sizes_attr', 10, 2 );
/**
* Filter the `sizes` value in the header image markup.
* @param string $html The HTML image tag markup being filtered.
* @param object $header The custom header object returned by 'get_custom_header()'.
* @param array $attr Array of the attributes for the image tag.
* @return string The filtered header image HTML.
*/
function newzer_header_image_tag( $html, $header, $attr ) {
if ( isset( $attr['sizes'] ) ) {
$html = str_replace( $attr['sizes'], '100vw', $html );
}
return $html;
}
add_filter( 'get_header_image_tag', 'newzer_header_image_tag', 10, 3 );
/**
* Add custom image sizes attribute to enhance responsive image functionality for post thumbnails.
* @param array $attr Attributes for the image markup.
* @param int $attachment Image attachment ID.
* @param array $size Registered image size or flat array of height and width dimensions.
* @return array The filtered attributes for the image markup.
*/
function newzer_post_thumbnail_sizes_attr( $attr, $attachment, $size ) {
if ( is_archive() || is_search() || is_home() ) {
$attr['sizes'] = '(max-width: 767px) 89vw, (max-width: 1000px) 54vw, (max-width: 1071px) 543px, 580px';
} else {
$attr['sizes'] = '100vw';
}
return $attr;
}
add_filter( 'wp_get_attachment_image_attributes', 'newzer_post_thumbnail_sizes_attr', 10, 3 );
/**
* Use front-page.php when Front page displays is set to a static page.
*
* @param string $template front-page.php.
*
* @return string The template to be used: blank if is_home() is true (defaults to index.php), else $template.
*/
function newzer_front_page_template( $template ) {
return is_home() ? '' : $template;
}
add_filter( 'frontpage_template', 'newzer_front_page_template' );
/**
* Modifies tag cloud widget arguments to display all tags in the same font size and use list format for better accessibility.
*
* @param array $args Arguments for tag cloud widget.
* @return array The filtered arguments for tag cloud widget.
*/
function newzer_widget_tag_cloud_args( $args ) {
$args['largest'] = 12;
$args['smallest'] = 12;
$args['unit'] = 'px';
$args['format'] = 'list';
return $args;
}
add_filter( 'widget_tag_cloud_args', 'newzer_widget_tag_cloud_args' );
/**
* Custom template tags for this theme.
*/
require get_parent_theme_file_path( '/include/template-tags.php' );
/**
* Additional features to allow styling of the templates.
*/
require get_parent_theme_file_path( '/include/template-functions.php' );
/**
* Customizer additions.
*/
require get_parent_theme_file_path( '/include/customizer.php' );
/**
* Widgets
*/
require get_template_directory() . '/widgets/widgets-init.php';
/**
* SVG icons functions and filters.
*/
require get_parent_theme_file_path( '/include/icon-functions.php' );
/**
* breadcrumb.
*/
require get_parent_theme_file_path( '/template-parts/header/breadcrumb.php' );
/**
* hooks function.
*/
require get_parent_theme_file_path( '/include/hooks.php' );
/**
* hooks function.
*/
require get_parent_theme_file_path( '/include/meta-box.php' );
/**
* Filter the except length to 30 words.
*
* @param int $length Excerpt length.
* @return int (Maybe) modified excerpt length.
*/
function newzer_custom_excerpt_length( $length ) {
if( is_admin() ) return $length;
return 20 ;
}
add_filter( 'excerpt_length', 'newzer_custom_excerpt_length');