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

Good news for Pakistanis from US Homeland Security

News Desk
2017-02-07

WASHINGTON: Homeland Security Secretary John Kelly told a congressional panel on Tuesday that the United States is not considering adding...

Iran threats to attack US Navy base in Bahrain in counter attack

News Desk
2017-02-07

If Iran were attacked, it would retaliate against the US Navy base in Bahrain as well as Israel, a senior...

British House of Commons speaker rises against Donald Trump

News Desk
2017-02-07

Speaker British House of Commons John Bercow has opposed the plan of US President Donald Trump to address the country’s...

Iranian Supreme leader Ayatollah Ali Khamenei lashes out at US

News Desk
2017-02-07

Iranian Supreme Leader Ayatollah Ali Khamenei dismissed US President Donald Trump’s warning to Tehran to stop its missile tests, and...

Trump – Netanyahu duo flexing muscles against Iran

News Desk
2017-02-07

Seizing on an Iranian missile test, Israeli Prime Minister Benjamin Netanyahu and new U.S. President Donald Trump are nearing common...

America s journey towards a Military Coup kicks off?

News Desk
2017-02-06

A former Defense Department official under the Obama administration has raised the specter of a military coup to remove President...

Donald Trump blasts courts for blocking travel ban, warns of peril

News Desk
2017-02-06

PALM BEACH: (APP) President Donald Trump blasted the federal courts for a second day in a row on Sunday after...

Donald Trump under fire for saying he respects killer Putin

News Desk
2017-02-06

PALM BEACH: (APP) President Donald Trump is drawing fire from Republicans and Democrats alike after playing down political assassinations in...

US Senator begged pardon from Pakistanis

News Desk
2017-02-06

LOS VEGAS: A US senator has blasted President Donald Trump’s decision of imposing travel curbs against seven Muslim states barring...

Trump agree to meet NATO leaders in Europe in May

News Desk
2017-02-06

US President Donald Trump has agreed to meet NATO leaders in Europe in May. He was talking to NATO Secretary...

Previous Next