tag in the document head, and expect WordPress to * provide it for us. */ add_theme_support( 'title-tag' ); add_theme_support( 'custom-logo' ); $defaults = array( 'default-color' => '', 'default-image' => '', 'default-repeat' => '', 'default-position-x' => '', 'default-attachment' => '', 'wp-head-callback' => 'todaynews_custom_background_cb', 'admin-head-callback' => '', 'admin-preview-callback' => '' ); add_theme_support( 'custom-background', $defaults); add_theme_support( 'custom-header' ); /* * 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_image_size( 'todaynews-featured-image', 2000, 1200, true ); add_image_size( 'todaynews-thumbnail-avatar', 100, 100, true ); // Set the default content width. $GLOBALS['content_width'] = 525; // This theme uses wp_nav_menu() in two locations. register_nav_menus( array( 'primary' => __( 'Primary Menu', 'today-news' ), ) ); /* * 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', 'script', 'style', ) ); /* * Enable support for Post Formats. * * See: https://wordpress.org/support/article/post-formats/ */ add_theme_support( 'post-formats', array( 'video', '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', todaynews_fonts_url() ) ); // Load regular editor styles into the new block-based editor. add_theme_support( 'editor-styles' ); // Load default block styles. add_theme_support( 'wp-block-styles' ); // Add support for responsive embeds. add_theme_support( 'responsive-embeds' ); } add_action( 'after_setup_theme', 'todaynews_setup' ); /** * Register custom fonts. */ function todaynews_fonts_url() { $fonts_url = ''; /* * translators: If there are characters in your language that are not supported * by Libre Franklin, translate this to 'off'. Do not translate into your own language. */ $libre_franklin = _x( 'on', 'Libre Franklin font: on or off', 'today-news' ); if ( 'off' !== $libre_franklin ) { $font_families = array(); $font_families[] = 'Libre Franklin:300,300i,400,400i,600,600i,800,800i'; $query_args = array( 'family' => urlencode( implode( '|', $font_families ) ), 'subset' => urlencode( 'latin,latin-ext' ), 'display' => urlencode( 'fallback' ), ); $fonts_url = add_query_arg( $query_args, 'https://fonts.googleapis.com/css' ); } return esc_url_raw( $fonts_url ); } /** * Register widget area. * * @link https://developer.wordpress.org/themes/functionality/sidebars/#registering-a-sidebar */ function todaynews_widgets_init() { register_sidebar( array( 'name' => __( 'Footer', 'today-news' ), 'id' => 'footer-sidebar', 'description' => __( 'Add widgets here to appear in your footer.', 'today-news' ), 'before_widget' => '
', 'after_widget' => '
', 'before_title' => '

', 'after_title' => '

', ) ); register_sidebar( array( 'name' => __( 'Home Content', 'today-news' ), 'id' => 'home-content', 'description' => __( 'Add widgets here to appear in your home content area.', 'today-news' ), 'before_widget' => '
', 'after_widget' => '
', 'before_title' => '

', 'after_title' => '

', ) ); register_sidebar( array( 'name' => __( 'Home Header', 'today-news' ), 'id' => 'home-header', 'description' => __( 'Add widgets here to appear in your home header area.', 'today-news' ), 'before_widget' => '
', 'after_widget' => '
', 'before_title' => '

', 'after_title' => '

', ) ); register_sidebar( array( 'name' => __( 'Right', 'today-news' ), 'id' => 'sidebar_right', 'description' => __( 'Add widgets here to appear in your right sidebar area.', 'today-news' ), 'before_widget' => '
', 'after_widget' => '
', 'before_title' => '

', 'after_title' => '

', ) ); register_sidebar( array( 'name' => __( 'Single', 'today-news' ), 'id' => 'sidebar_single', 'description' => __( 'Add widgets here to appear in your single area.', 'today-news' ), 'before_widget' => '
', 'after_widget' => '
', 'before_title' => '

', 'after_title' => '

', ) ); } add_action( 'widgets_init', 'todaynews_widgets_init' ); /** * Handles JavaScript detection. * * Adds a `js` class to the root `` element when JavaScript is detected. * * @since Twenty Seventeen 1.0 */ function todaynews_javascript_detection() { echo "\n"; } add_action( 'wp_head', 'todaynews_javascript_detection', 0 ); /** * Add a pingback url auto-discovery header for singularly identifiable articles. */ function todaynews_pingback_header() { if ( is_singular() && pings_open() ) { printf( '' . "\n", esc_url( get_bloginfo( 'pingback_url' ) ) ); } } add_action( 'wp_head', 'todaynews_pingback_header' ); /** * Enqueues scripts and styles. */ function todaynews_scripts() { // Add custom fonts, used in the main stylesheet. wp_enqueue_style( 'today-news-fonts', todaynews_fonts_url(), array(), null ); // Theme stylesheet. wp_enqueue_style( 'today-news-style', get_stylesheet_uri(), array(), '20190507' ); wp_enqueue_style( 'bootstrap', get_template_directory_uri() . '/assets/css/bootstrap.min.css', array(), '4.1.3', 'all' ); wp_enqueue_style( 'today-news-wpb-google-fonts', 'https://fonts.googleapis.com/css?family=Public+Sans&display=swap', false ); wp_enqueue_style( 'today-news-wpb-google-fonts', 'https://fonts.googleapis.com/css?family=Archivo:500|Open+Sans:300,700', false ); wp_enqueue_style( 'today-news-wpb-google-fonts', 'https://fonts.googleapis.com/css?family=Roboto&display=swap', false ); wp_enqueue_style( 'today-news-wpb-google-fonts', 'https://fonts.googleapis.com/css?family=Noto+Sans+TC&display=swap', false ); wp_enqueue_style( 'today-news-wpb-google-fonts', 'https://fonts.googleapis.com/css?family=PT+Mono&display=swap', false ); wp_enqueue_style('today-news-google', 'https://fonts.googleapis.com/css?family=Droid+Sans:400,700', false); // Theme block stylesheet. wp_enqueue_style( 'today-news-block-style', get_theme_file_uri( '/assets/css/blocks.css' ), array( 'todaynews-style' ), '20190105' ); wp_enqueue_style( 'today-news-font-awesome-style', get_theme_file_uri( '/assets/font-awesome/css/all.css'), array(), '5.12.0' , 'all'); wp_enqueue_style('today-news-baguetteBox-css', get_theme_file_uri( '/assets/css/baguetteBox.min.css' ), array(), '1.8.1', 'all'); // Load the Internet Explorer 9 specific stylesheet, to fix display issues in the Customizer. if ( is_customize_preview() ) { wp_enqueue_style( 'today-news-ie9', get_theme_file_uri( '/assets/css/ie9.css' ), array( 'todaynews-style' ), '20161202' ); wp_style_add_data( 'today-news-ie9', 'conditional', 'IE 9' ); } // Load the Internet Explorer 8 specific stylesheet. wp_enqueue_style( 'today-news-ie8', get_theme_file_uri( '/assets/css/ie8.css' ), array( 'todaynews-style' ), '20161202' ); wp_style_add_data( 'today-news-ie8', 'conditional', 'lt IE 9' ); // Load the html5 shiv. wp_enqueue_script( 'html5', get_theme_file_uri( '/assets/js/html5.js' ), array(), '20161020' ); wp_script_add_data( 'html5', 'conditional', 'lt IE 9' ); wp_enqueue_script( 'today-news-skip-link-focus-fix', get_theme_file_uri( '/assets/js/skip-link-focus-fix.js' ), array(), '20161114', true ); $todaynews_l10n = array( 'quote' => todaynews_get_svg( array( 'icon' => 'quote-right' ) ), ); if ( has_nav_menu( 'top' ) ) { wp_enqueue_script( 'today-news-navigation', get_theme_file_uri( '/assets/js/navigation.js' ), array( 'jquery' ), '20161203', true ); $todaynews_l10n['expand'] = __( 'Expand child menu', 'today-news' ); $todaynews_l10n['collapse'] = __( 'Collapse child menu', 'today-news' ); $todaynews_l10n['icon'] = todaynews_get_svg( array( 'icon' => 'angle-down', 'fallback' => true, ) ); } wp_enqueue_script( 'jquery'); wp_enqueue_script( 'today-news-boot2', get_theme_file_uri( '/assets/js/popper.min.js' ), array( 'jquery' ), '', true ); wp_enqueue_script( 'today-news-boot4', get_theme_file_uri( '/assets/js/jquery.min.js' ), array( 'jquery' ), '3.1.0', true ); wp_enqueue_script( 'todaynews-global', get_theme_file_uri( '/assets/js/global.js' ), array( 'jquery' ), '20190121', true ); wp_enqueue_script( 'jquery-scrollto', get_theme_file_uri( '/assets/js/jquery.scrollTo.js' ), array( 'jquery' ), '2.1.2', true ); wp_enqueue_script( 'today-news-baquetteBox', get_theme_file_uri( '/assets/js/baguetteBox.min.js' ), array( 'jquery' ), '1.8.1',true ); wp_enqueue_script('bootstrap', get_template_directory_uri() . '/assets/js/bootstrap.min.js', array( 'jquery' ), '4.1.3', true ); wp_localize_script( 'today-news-skip-link-focus-fix', 'todaynewsScreenReaderText', $todaynews_l10n ); if ( is_singular() && comments_open() && get_option( 'thread_comments' ) ) { wp_enqueue_script( 'comment-reply' ); } } add_action( 'wp_enqueue_scripts', 'todaynews_scripts' ); /** * Enqueues styles for the block-based editor. * * @since Today News */ function todaynews_block_editor_styles() { // Block styles. wp_enqueue_style( 'today-news-block-editor-style', get_theme_file_uri( '/assets/css/editor-blocks.css' ), array(), '20190328' ); // Add custom fonts. wp_enqueue_style( 'today-news-fonts', todaynews_fonts_url(), array(), null ); } add_action( 'enqueue_block_editor_assets', 'todaynews_block_editor_styles' ); /** * Add custom image sizes attribute to enhance responsive image functionality * for content images. * * @since Today News * * @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 todaynews_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', 'todaynews_content_image_sizes_attr', 10, 2 ); /** * Filter the `sizes` value in the header image markup. * * @since Today News * * @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 todaynews_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', 'todaynews_header_image_tag', 10, 3 ); /** * Add custom image sizes attribute to enhance responsive image functionality * for post thumbnails. * * @since Today News * * @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 todaynews_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', 'todaynews_post_thumbnail_sizes_attr', 10, 3 ); /** * Modifies tag cloud widget arguments to display all tags in the same font size * and use list format for better accessibility. * * @since Today News * * @param array $args Arguments for tag cloud widget. * @return array The filtered arguments for tag cloud widget. */ function todaynews_widget_tag_cloud_args( $args ) { $args['largest'] = 1; $args['smallest'] = 1; $args['unit'] = 'em'; $args['format'] = 'list'; return $args; } add_filter( 'widget_tag_cloud_args', 'todaynews_widget_tag_cloud_args' ); /** * Get unique ID. * * This is a PHP implementation of Underscore's uniqueId method. A static variable * contains an integer that is incremented with each call. This number is returned * with the optional prefix. As such the returned value is not universally unique, * but it is unique across the life of the PHP process. * * @since Today News * @see wp_unique_id() Themes requiring WordPress 5.0.3 and greater should use this instead. * * @staticvar int $id_counter * * @param string $prefix Prefix for the returned ID. * @return string Unique ID. */ function todaynews_unique_id( $prefix = '' ) { static $id_counter = 0; if ( function_exists( 'wp_unique_id' ) ) { return wp_unique_id( $prefix ); } return $prefix . (string) ++$id_counter; } /** * Implement the Custom Header feature. */ require get_parent_theme_file_path( '/inc/custom-header.php' ); require get_parent_theme_file_path( '/inc/widgets.php' ); /** * Custom template tags for this theme. */ require get_parent_theme_file_path( '/inc/template-tags.php' ); /** * Additional features to allow styling of the templates. */ require get_parent_theme_file_path( '/inc/template-functions.php' ); /** * Customizer additions. */ require get_parent_theme_file_path( '/inc/customizer.php' ); /** * SVG icons functions and filters. */ require get_parent_theme_file_path( '/inc/icon-functions.php' ); require get_parent_theme_file_path( '/inc/ajax.php' ); /* Post Views */ if ( ! function_exists( 'getPostViews' ) ) { function getPostViews($postID){ $count_key = 'post_views_count'; $count = get_post_meta($postID, $count_key, true); if($count==''){ delete_post_meta($postID, $count_key); add_post_meta($postID, $count_key, '0'); return "0 View"; } return $count.' Views'; } } if ( ! function_exists( 'setPostViews' ) ) { function setPostViews($postID) { $count_key = 'post_views_count'; $count = get_post_meta($postID, $count_key, true); if($count==''){ $count = 0; delete_post_meta($postID, $count_key); add_post_meta($postID, $count_key, '0'); }else{ $count++; update_post_meta($postID, $count_key, $count); } } } // Remove issues with prefetching adding extra views remove_action( 'wp_head', 'adjacent_posts_rel_link_wp_head', 10, 0); /* Posts Excerpt */ function wpdocs_excerpt_more( $more ) { return '...'; } add_filter( 'excerpt_more', 'wpdocs_excerpt_more' ); /* Excerpt Length */ function wpdocs_custom_excerpt_length( $length ) { return 20; } add_filter( 'excerpt_length', 'wpdocs_custom_excerpt_length', 999 ); if ( ! function_exists( 'meks_time_ago' ) ) { /* Function which displays your post date in time ago format */ function meks_time_ago() { return human_time_diff( get_the_time( 'U' ), current_time( 'timestamp' ) ).' '.__( 'ago', 'today-news' ); } } function remove_admin_login_header() { remove_action('wp_head', '_admin_bar_bump_cb'); } add_action('get_header', 'remove_admin_login_header'); if ( ! function_exists( 'get_images_from_media_library' ) ) { function get_images_from_media_library() { $args = array( 'post_type' => 'attachment', 'post_mime_type' =>'image', 'post_status' => 'inherit', 'posts_per_page' => 5, 'orderby' => 'rand' ); $query_images = new WP_Query( $args ); $images = array(); foreach ( $query_images->posts as $image) { $images[]= $image->guid; } return $images; } } if ( ! function_exists( 'display_images_from_media_library' ) ) { function display_images_from_media_library() { $imgs = get_images_from_media_library(); $html = ''; return $html; } } if ( ! function_exists( 'force_comment_author_url' ) ) { function force_comment_author_url($comment) { // does the comment have a valid author URL? $no_url = !$comment->comment_author_url || $comment->comment_author_url == 'http://'; if ($comment->user_id && $no_url) { // comment was written by a registered user but with no author URL $comment->comment_author_url = 'http://www.example.com/?author=' . $comment->user_id; } return $comment; } } add_filter('get_comment', 'force_comment_author_url'); /** * Categories color * * */ /** * Define categories lists in array */ $todaynews_lite_categories = get_categories( array( 'hide_empty' => true ) ); foreach ( $todaynews_lite_categories as $todaynews_lite_category ) { $todaynews_lite_cat_array[$todaynews_lite_category->term_id] = $todaynews_lite_category->cat_name.' ('. $todaynews_lite_category->category_count.')'; } if ( ! function_exists( 'todaynews_lite_dynamic_css' ) ) { function todaynews_lite_dynamic_css(){ $custom_css = ""; global $todaynews_lite_cat_array; if( $todaynews_lite_cat_array ): foreach ( $todaynews_lite_cat_array as $key => $value ) { $cat_color = get_option('todaynews_lite_cat_color_' . $key, '#e52d6d'); ?>