/* Plugin Name: Optimized Inline Related Articles v5.0 (Ads Removed) */ add_filter('the_content', 'optimized_inline_related_articles_v5', 99); function optimized_inline_related_articles_v5($content) { if (!is_single() || !is_main_query()) return $content; global $post; $used_posts = [$post->ID]; $paragraphs = explode('

', $content); $total_paragraphs = count($paragraphs); if ($total_paragraphs < 6) return $content; // ------------------------ // TAG BASED RELATED POSTS // ------------------------ $tags = wp_get_post_tags($post->ID); if (!$tags) return $content; $tag_ids = wp_list_pluck($tags, 'term_id'); $related_query = new WP_Query([ 'tag__in' => $tag_ids, 'post__not_in' => $used_posts, 'posts_per_page' => 15, 'ignore_sticky_posts' => 1, ]); $related_posts = []; if ($related_query->have_posts()) { while ($related_query->have_posts()) { $related_query->the_post(); $post_tags = wp_get_post_tags(get_the_ID()); $shared_tags = count(array_intersect($tag_ids, wp_list_pluck($post_tags,'term_id'))); $related_posts[] = [ 'id' => get_the_ID(), 'title' => get_the_title(), 'link' => get_permalink(), 'shared_tags' => $shared_tags ]; } wp_reset_postdata(); } if (empty($related_posts)) return $content; usort($related_posts, fn($a,$b) => $b['shared_tags'] - $a['shared_tags']); // ===================================================== // INLINE INSERT (TOP SECTION) // ===================================================== $top_positions = [11,15,19]; $count = 0; foreach($top_positions as $pos){ if(!isset($related_posts[$count])) break; if($pos >= $total_paragraphs) continue; $rp = $related_posts[$count]; $inline_html = "
Read More: {$rp['title']}
"; $paragraphs[$pos] .= $inline_html; $count++; } // ===================================================== // BOTTOM INSERT (UNCHANGED LOGIC, NO ADS FILTER) // ===================================================== $bottom_positions = []; for($i=floor($total_paragraphs*0.45); $i<$total_paragraphs; $i++){ $bottom_positions[] = $i; } $max_bottom = min(3, count($related_posts)-$count); if($max_bottom > 0 && count($bottom_positions) > 0){ $interval = max(1, floor(count($bottom_positions)/$max_bottom)); for($b=0;$b<$max_bottom;$b++){ $pos_index = $b * $interval; if(!isset($bottom_positions[$pos_index])) break; $pos = $bottom_positions[$pos_index]; if(!isset($related_posts[$count])) break; $rp = $related_posts[$count]; $inline_html = "
Read More: {$rp['title']}
"; $paragraphs[$pos] .= $inline_html; $count++; } } return implode('

', $paragraphs); } Donald Trump
Follow
WhatsApp

US Senate, House of Representatives pass bill to temporarily end shutdown

News Desk
2019-01-26

US President Donald Trump has yielded to political pressure to end the longest US government shutdown in history. After 35...

Trump says he will declare an emergency if he doesn t reach a border deal

News Desk
2019-01-26

US President Donald Trump has said that he will declare a national emergency if he doesn’t eventually reach a deal...

US President Donald Trump surrenders

News Desk
2019-01-26

WASHINGTON – US President Donald Trump has agreed to end a 35-day-oldpartial U.S. government shutdown. The decision came after a...

John Kerry to Trump: ‘Resign’

News Desk
2019-01-23

DAVOS: Former US secretary of state John Kerry said Tuesday he was not ruling out another tilt at the White...

US President Donald Trump made 8,158 false or misleading claims since taking office: Report

News Desk
2019-01-22

WASHINGTON – US President Donald Trump has made 8,158 false or misleadingclaims since taking office, according to a media report....

US,Turkey agree to continue to pursue negotiated settlement for northeastern Syria

News Desk
2019-01-21

The United States and Turkey have agreed to continue to pursue a negotiated settlement for northeastern Syria. White House spokeswoman...

Trump denounces Democrats for rejecting proposals to end govt shutdown

News Desk
2019-01-21

US President Donald Trump has denounced House of Representative Speaker, Nancy Pelosi, and the Democrats for rejecting his proposals to...

Trump offers 3-year extension of protection for dreamers in exchange for border wall

News Desk
2019-01-20

The US President Donald Trump has offered three years of protections for young undocumented immigrants known as “Dreamers,” as well...

Trump to meet N.Korean envoy Kim Yong Chol: White House

News Desk
2019-01-19

Washington: US President Donald Trump is meeting with North Korean envoy Kim Yong Chol to discuss negotiations on the country’s...

Trump to meet for 2nd time with N. Korean leader in Feb

News Desk
2019-01-19

The US President Donald Trump will meet for the second time with North Korean leader Kim Jong Un in February,...

Previous Next