ID, 'morenews-meta-content-alignment', true);
if (!empty($post_options)) {
$page_layout = $post_options;
} else {
$page_layout = $global_alignment;
}
}
// Check if single.
if ($post && is_singular()) {
$global_single_content_mode = morenews_get_option('global_single_content_mode');
$post_single_content_mode = get_post_meta($post->ID, 'morenews-meta-content-mode', true);
if (!empty($post_single_content_mode)) {
$classes[] = $post_single_content_mode;
} else {
$classes[] = $global_single_content_mode;
}
}
// Check if single.
if ($post && is_singular()) {
$single_post_title_view = morenews_get_option('single_post_title_view');
$classes[] = 'single-post-title-' . $single_post_title_view;
}
if (is_front_page()) {
$frontpage_layout = morenews_get_option('frontpage_content_alignment');
if (!empty($frontpage_layout)) {
$page_layout = $frontpage_layout;
}
}
if (!is_front_page() && is_home()) {
$page_layout = $global_alignment;
}
if ($page_layout == 'align-content-right') {
if (is_front_page() && !is_home()) {
if (class_exists('WooCommerce')) {
if (is_shop()) {
if (is_active_sidebar('sidebar-1')) {
$classes[] = 'align-content-right';
} else {
$classes[] = 'full-width-content';
}
} else {
if (is_active_sidebar('home-sidebar-widgets')) {
$classes[] = 'align-content-right';
} else {
$classes[] = 'full-width-content';
}
}
} else {
if (is_active_sidebar('home-sidebar-widgets')) {
$classes[] = 'align-content-right';
} else {
$classes[] = 'full-width-content';
}
}
} else {
if (is_active_sidebar('sidebar-1')) {
$classes[] = 'align-content-right';
} else {
$classes[] = 'full-width-content';
}
}
} elseif ($page_layout == 'full-width-content') {
$classes[] = 'full-width-content';
} else {
if (is_front_page() && !is_home()) {
if (class_exists('WooCommerce')) {
if (is_shop()) {
if (is_active_sidebar('sidebar-1')) {
$classes[] = 'align-content-left';
} else {
$classes[] = 'full-width-content';
}
} else {
if (is_active_sidebar('home-sidebar-widgets')) {
$classes[] = 'align-content-left';
} else {
$classes[] = 'full-width-content';
}
}
} else {
if (is_active_sidebar('home-sidebar-widgets')) {
$classes[] = 'align-content-left';
} else {
$classes[] = 'full-width-content';
}
}
} else {
if (is_active_sidebar('sidebar-1')) {
$classes[] = 'align-content-left';
} else {
$classes[] = 'full-width-content';
}
}
}
$banner_layout = morenews_get_option('global_site_layout_setting');
if ($banner_layout == 'wide') {
$classes[] = 'af-wide-layout';
} elseif ($banner_layout == 'full') {
$classes[] = 'af-full-layout';
} else {
$classes[] = 'af-boxed-layout';
$global_topbottom_gaps = morenews_get_option('global_site_layout_topbottom_gaps');
if ($global_topbottom_gaps) {
$classes[] = 'aft-enable-top-bottom-gaps';
}
}
return $classes;
}
add_filter('body_class', 'morenews_body_classes');
function morenews_is_elementor()
{
global $post;
return \Elementor\Plugin::$instance->db->is_built_with_elementor($post->ID);
}
/**
* Add a pingback url auto-discovery header for singularly identifiable articles.
*/
function morenews_pingback_header()
{
if (is_singular() && pings_open()) {
echo ' ';
}
}
add_action('wp_head', 'morenews_pingback_header');
/**
* Get posts based on filter type (category, tag, view count, comment count, etc.).
*
* @since MoreNews 1.0.0
*
* @param int $number_of_posts Number of posts to retrieve (max 50).
* @param int $term_id Category or tag ID depending on filter.
* @param string $filterby Filter type: 'cat', 'tag', 'view', 'comment', 'recent'.
* @param array $extra_args Optional extra WP_Query args (offset, date_query etc).
* @return WP_Query WP_Query object.
*/
if ( ! function_exists( 'morenews_get_posts' ) ) {
function morenews_get_posts( $number_of_posts = 5, $term_id = 0, $filterby = 'cat', $extra_args = array() ) {
$number_of_posts = absint( $number_of_posts );
$number_of_posts = min( $number_of_posts, 20 ); // Cap to safe max.
$term_id = absint( $term_id );
$filterby = sanitize_key( $filterby );
$args = array(
'post_type' => 'post',
'posts_per_page' => $number_of_posts,
'post_status' => 'publish',
'ignore_sticky_posts' => true,
'order' => 'DESC',
'no_found_rows' => true,
);
switch ( $filterby ) {
case 'tag':
if ( $term_id > 0 ) {
$args['tag_id'] = $term_id;
}
$args['orderby'] = 'date';
break;
case 'comment':
$args['orderby'] = 'comment_count';
break;
case 'recent':
// Possibly use date_query
$args['orderby'] = 'date';
break;
case 'cat':
default:
if ( $term_id > 0 ) {
$args['cat'] = $term_id;
}
$args['orderby'] = 'date';
break;
}
// Merge in any extra query args
if ( is_array( $extra_args ) && ! empty( $extra_args ) ) {
$args = array_merge( $args, $extra_args );
}
/**
* Allow overriding query args.
*
* @param array $args Final WP_Query arguments.
* @param int $number_of_posts Passed number of posts.
* @param int $term_id Term ID.
* @param string $filterby Filter type.
* @param array $extra_args Extra args passed.
*/
$args = apply_filters( 'morenews_get_posts_args', $args, $number_of_posts, $term_id, $filterby, $extra_args );
return new WP_Query( $args );
}
}
/**
* Returns no image url.
*
* @since MoreNews 1.0.0
*/
if (!function_exists('morenews_post_format')) :
function morenews_post_format($post_id)
{
$post_format = get_post_format($post_id);
switch ($post_format) {
case "image":
$post_format = "
";
break;
case "video":
$post_format = "
";
break;
case "gallery":
$post_format = "
";
break;
default:
$post_format = "";
}
echo wp_kses_post($post_format);
}
endif;
if (!function_exists('morenews_get_block')) :
/**
*
* @param null
*
* @return null
*
* @since MoreNews 1.0.0
*
*/
function morenews_get_block($block = 'grid', $section = 'post')
{
get_template_part('inc/hooks/blocks/block-' . $section, $block);
}
endif;
if (!function_exists('morenews_archive_title')) :
/**
*
* @param null
*
* @return null
*
* @since MoreNews 1.0.0
*
*/
function morenews_archive_title($title)
{
if (is_category()) {
$title = single_cat_title('', false);
} elseif (is_tag()) {
$title = single_tag_title('', false);
} elseif (is_author()) {
$title = '' . get_the_author() . ' ';
} elseif (is_post_type_archive()) {
$title = post_type_archive_title('', false);
} elseif (is_tax()) {
$title = single_term_title('', false);
}
return $title;
}
endif;
add_filter('get_the_archive_title', 'morenews_archive_title');
/* Display Breadcrumbs */
if (!function_exists('morenews_get_breadcrumb')) :
/**
* Simple breadcrumb.
*
* @since 1.0.0
*/
function morenews_get_breadcrumb()
{
$enable_breadcrumbs = morenews_get_option('enable_breadcrumb');
if (1 != $enable_breadcrumbs) {
return;
}
// Bail if Home Page.
if (is_front_page() || is_home()) {
return;
}
$select_breadcrumbs = morenews_get_option('select_breadcrumb_mode');
?>
'div',
'show_browse' => false,
);
breadcrumb_trail($breadcrumb_args);
}
endif;
/**
* Front-page main banner section layout
*/
if (!function_exists('morenews_front_page_main_section_scope')) {
function morenews_front_page_main_section_scope()
{
$morenews_hide_on_blog = morenews_get_option('disable_main_banner_on_blog_archive');
if ($morenews_hide_on_blog) {
if (is_front_page()) {
do_action('morenews_action_front_page_main_section');
}
} else {
if (is_front_page() || is_home()) {
do_action('morenews_action_front_page_main_section');
}
}
}
}
add_action('morenews_action_front_page_main_section_scope', 'morenews_front_page_main_section_scope');
/* Display Breadcrumbs */
if (!function_exists('morenews_excerpt_length')) :
/**
* Simple excerpt length.
*
* @since 1.0.0
*/
function morenews_excerpt_length($length)
{
$morenews_global_excerpt_length = morenews_get_option('global_excerpt_length');
if (is_admin()) {
return $length;
}
return $morenews_global_excerpt_length;
}
endif;
add_filter('excerpt_length', 'morenews_excerpt_length', 999);
/* Display Breadcrumbs */
if (!function_exists('morenews_excerpt_more')) :
/**
* Simple excerpt more.
*
* @since 1.0.0
*/
function morenews_excerpt_more($more)
{
if (is_admin()) {
return $more;
}
global $post;
$morenews_global_read_more_texts = morenews_get_option('global_read_more_texts');
//return $morenews_global_read_more_texts;
return '';
}
endif;
add_filter('excerpt_more', 'morenews_excerpt_more');
if (!function_exists('morenews_get_the_excerpt')) :
/**
* Simple excerpt more with descriptive "Read More" links.
*
* @since 1.0.0
*/
function morenews_get_the_excerpt($post_id)
{
if (empty($post_id)) {
return;
}
// Get the default excerpt for the post.
$morenews_default_excerpt = get_the_excerpt($post_id);
// Retrieve the "Read More" text from theme options.
$morenews_global_read_more_texts = morenews_get_option('global_read_more_texts');
// Get the post title to make the "Read More" link more descriptive.
$post_title = get_the_title($post_id);
// Create a descriptive "Read More" link, making it translation-ready.
// Use `sprintf()` to dynamically insert the translated post title.
$morenews_read_more = sprintf(
'',
esc_url(get_permalink($post_id)), // %1$s: Link to the post.
esc_attr(sprintf(__('Read more about %s', 'morenews'), $post_title)), // %2$s: Aria-label, translation-ready.
esc_html($morenews_global_read_more_texts), // %3$s: The main "Read More" text.
esc_html(sprintf(__('Read more about %s', 'morenews'), $post_title)) // %4$s: Screen-reader text, translation-ready.
);
// Get the global excerpt length from theme options.
$morenews_global_excerpt_length = morenews_get_option('global_excerpt_length');
// Split the excerpt into words and truncate based on the defined length.
$excerpt = explode(' ', $morenews_default_excerpt, $morenews_global_excerpt_length);
if (count($excerpt) >= $morenews_global_excerpt_length) {
array_pop($excerpt);
$excerpt = implode(" ", $excerpt) . '...';
} else {
$excerpt = implode(" ", $excerpt);
}
// Remove any shortcodes or unwanted characters from the excerpt.
$excerpt = preg_replace('`[[^]]*]`', '', $excerpt);
// Append the "Read More" link to the excerpt.
$excerpt = $excerpt . $morenews_read_more;
return $excerpt;
}
endif;
/* Display Pagination */
if (!function_exists('morenews_numeric_pagination')) :
/**
* Simple excerpt more.
*
* @since 1.0.0
*/
function morenews_numeric_pagination()
{
the_posts_pagination(array(
'mid_size' => 3,
'prev_text' => __('Previous', 'morenews'),
'next_text' => __('Next', 'morenews'),
));
}
endif;
// /* Word read count Pagination */
// if (!function_exists('morenews_count_content_words')) :
// /**
// * @param $content
// *
// * @return string
// */
// function morenews_count_content_words($post_id)
// {
// $morenews_show_read_mins = morenews_get_option('global_show_min_read');
// if ($morenews_show_read_mins == 'yes') {
// $content = apply_filters('the_content', get_post_field('post_content', $post_id));
// $morenews_read_words = morenews_get_option('global_show_min_read_number');
// $morenews_decode_content = html_entity_decode($content);
// $morenews_filter_shortcode = do_shortcode($morenews_decode_content);
// $morenews_strip_tags = wp_strip_all_tags($morenews_filter_shortcode, true);
// $morenews_count = str_word_count($morenews_strip_tags);
// $morenews_word_per_min = (absint($morenews_count) / $morenews_read_words);
// $morenews_word_per_min = ceil($morenews_word_per_min);
// if (absint($morenews_word_per_min) > 0) {
// $word_count_strings = sprintf(__("%s min read", 'morenews'), number_format_i18n($morenews_word_per_min));
// if ('post' == get_post_type($post_id)) :
// echo '';
// echo esc_html($word_count_strings);
// echo ' ';
// endif;
// }
// }
// }
// endif;
if (!function_exists('morenews_count_content_words')) :
function morenews_count_content_words($post_id)
{
$morenews_show_read_mins = morenews_get_option('global_show_min_read');
if($morenews_show_read_mins == 'no'){
return;
}
// Posts only
if ('post' !== get_post_type($post_id)) {
return;
}
// Get pre-saved reading time (best performance)
$read_time = absint(get_post_meta($post_id, '_aft_read_time', true));
// If not available (older posts), fallback once
if (!$read_time) {
// Lightweight processing (DO NOT use the_content filter)
$content = get_post_field('post_content', $post_id);
// Fast cleanup
$clean_text = wp_strip_all_tags(strip_shortcodes($content), true);
// Fast word count
$word_count = str_word_count($clean_text);
// Words per minute
$wpm = absint(morenews_get_option('global_show_min_read_number'));
if (!$wpm) {
$wpm = 200;
}
$read_time = ceil($word_count / $wpm);
// Store so it never recalculates again
update_post_meta($post_id, '_aft_read_time', $read_time);
}
if ($read_time > 0) {
// Translatable singular/plural
$output = sprintf(
_n(
'%s minute read',
'%s minutes read',
$read_time,
'morenews'
),
number_format_i18n($read_time)
);
echo '' . esc_html($output) . ' ';
}
}
endif;
/**
* Check if given term has child terms
*
* @param Integer $term_id
* @param String $taxonomy
*
* @return Boolean
*/
function morenews_list_popular_taxonomies($taxonomy = 'post_tag', $title = "Popular Tags", $number = 5)
{
$popular_taxonomies = get_terms(array(
'taxonomy' => $taxonomy,
'number' => absint($number),
'orderby' => 'count',
'order' => 'DESC',
'hide_empty' => true,
));
$html = '';
if (isset($popular_taxonomies) && !empty($popular_taxonomies)) :
$html .= '';
if (!empty($title)) :
$html .= '
';
$html .= esc_html($title);
$html .= ' ';
endif;
$html .= '
';
$html .= '
';
endif;
echo wp_kses_post($html);
}
/**
* @param $post_id
* @param string $size
*
* @return mixed|string
*/
function morenews_get_freatured_image_url($post_id, $size = 'large')
{
$url = '';
if (has_post_thumbnail($post_id)) {
$thumb = wp_get_attachment_image_src(get_post_thumbnail_id($post_id), $size);
if (isset($thumb[0])) {
$url = $thumb[0];
}
} else {
$url = '';
}
return $url;
}
//Get attachment alt tag
if (!function_exists('morenews_get_img_alt')) :
function morenews_get_img_alt($attachment_ID)
{
// Get ALT
$thumb_alt = get_post_meta($attachment_ID, '_wp_attachment_image_alt', true);
// No ALT supplied get attachment info
if (empty($thumb_alt))
$attachment = get_post($attachment_ID);
// Use caption if no ALT supplied
if (empty($thumb_alt))
$thumb_alt = $attachment->post_excerpt;
// Use title if no caption supplied either
if (empty($thumb_alt))
$thumb_alt = $attachment->post_title;
// Return ALT
return trim(strip_tags($thumb_alt));
}
endif;
// Move Jetpack from the_content / the_excerpt to another position
function morenews_jptweak_remove_share()
{
if (is_singular('post')) {
remove_filter('the_content', 'sharing_display', 19);
remove_filter('the_excerpt', 'sharing_display', 19);
}
}
add_action('loop_start', 'morenews_jptweak_remove_share');
/**
* @param $post_id
*/
function morenews_get_comments_views_share($post_id)
{
$aft_post_type = get_post_type($post_id);
if ($aft_post_type !== 'post') {
return;
}
?>
get_global_options();
if (in_array('index', $global['show']) && (is_home() || is_front_page() || is_archive() || is_search() || in_array(get_post_type(), $global['show']))) :
?>
';
}
?>
';
}
endif;
}
function morenews_single_post_commtents_view($post_id)
{
?>
$url) {
if (strpos($url, $emoji_svg_url) !== false) {
unset($urls[$key]);
}
}
}
return $urls;
}
if (!function_exists('morenews_author_bio_box')) :
function morenews_author_bio_box()
{
if (!is_single()) {
return;
}
$allowed_post_types = apply_filters('morenews_author_bio_post_types', array('post'));
if (!in_array(get_post_type(), $allowed_post_types, true)) {
return;
}
$author_id = get_the_author_meta('ID');
$author_name = get_the_author();
$author_url = get_author_posts_url($author_id);
$website = get_the_author_meta('user_url');
// Get author role (optional)
$user = get_userdata( $author_id );
$role_name = '';
if ( $user && ! empty( $user->roles ) ) {
$role_name = ucfirst( $user->roles[0] );
}
?>
is_main_query() && $query->is_search() && ! is_admin() ) {
$query->set( 'post_type', 'post' ); // Include only posts
}
}
add_action( 'pre_get_posts', 'morenews_search_results' );