/* 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

Trump says he is determined to bring back US troops from Afghanistan, Syria

News Desk
2019-02-04

NEW YORK: US President Donald Trump says he’s determined to get out of “endless wars” in Afghanistan and Syria and...

Afghanistan War is bleeding US economy with 51 billion per annum, accepts Donald Trump

News Desk
2019-02-04

ISLAMABAD – US President Donald Trump has once again insisted that he willwithdraw his forces from Afghanistan. In an interview...

Donald Trump reaffirmed determination to pullout troops from Afghanistan, Syria endless wars

News Desk
2019-02-03

WASHINGTON – US President Donald Trump reaffirmed, in an interview airingSunday, his determination to pull US troops out of “endless...

Trump serious about Afghan withdrawal, Taliban says

News Desk
2019-02-02

Kabul: US President Donald Trump is serious about getting out of Afghanistan, the Taliban told AFP, outlining the “Islamic system”...

End of US Military foreign wars: Donald Trump likely to make historic announcement

News Desk
2019-02-02

WASHINGTON – President Donald Trump will reaffirm his intention to end USinvolvement in foreign military conflicts when he delivers his...

Donald Trump insists on US troops withdrawal from Afghanistan

News Desk
2019-02-01

ISLAMABAD – US President Donald Trump says serious negotiations on Afghanpeace are going on for the first time in the...

US President Donald Trump breaks silence over peace talks with Afghan Taliban

News Desk
2019-01-31

WASHINGTON – The U.S. President Donald Trump has hailed the ongoingnegotiations with the Taliban group to end the war in...

Trump once again vows to build wall on southern border with Mexico

News Desk
2019-01-28

United States President Donald Trump has once again vowed to build a wall on the southern border with Mexico. In...

Donald Trump lauds Pakistan, expressed desire to meet Pakistani PM Imran Khan

News Desk
2019-01-28

DUBAI – US President Donald Trump has lauded Pakistan role in Afghanistanpeace talks and has expressed desire to meet Pakistani...

Donald Trump may have shot himself in the foot

News Desk
2019-01-27

WASHINGTON – Donald Trump loves to make the pistol gesture when pronouncinghis “You’re fired” catchphrase. But in the tussle with...

Previous Next