134 lines
5.2 KiB
PHP
134 lines
5.2 KiB
PHP
<?php
|
|
/**
|
|
* Plugin Name: Nomadro AdSense Optimization
|
|
* Description: AdSense head code, trust schema, performance hygiene, and editorial CSS.
|
|
* Author: Nomadro
|
|
*/
|
|
|
|
if (!defined('ABSPATH')) {
|
|
exit;
|
|
}
|
|
|
|
const NOMADRO_ADSENSE_CLIENT = 'ca-pub-8461145959530971';
|
|
/** Filled by observability deploy (Umami website id for nomadro.com). */
|
|
const NOMADRO_UMAMI_WEBSITE_ID = 'REPLACE_UMAMI_WEBSITE_ID';
|
|
|
|
/** AdSense loader + ownership meta (site verification + ads) + Umami. */
|
|
add_action('wp_head', static function (): void {
|
|
$client = NOMADRO_ADSENSE_CLIENT;
|
|
echo '<meta name="google-adsense-account" content="' . esc_attr($client) . '">' . "\n";
|
|
echo '<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client='
|
|
. esc_attr($client) . '" crossorigin="anonymous"></script>' . "\n";
|
|
echo '<meta name="author" content="Nomadro Editorial">' . "\n";
|
|
echo '<meta name="theme-color" content="#f6f3ee">' . "\n";
|
|
// Deploy replaces REPLACE_UMAMI_WEBSITE_ID with a UUID; only emit when set.
|
|
if (preg_match('/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i', NOMADRO_UMAMI_WEBSITE_ID)) {
|
|
echo '<script defer src="https://umami.nomadro.com/script.js" data-website-id="'
|
|
. esc_attr(NOMADRO_UMAMI_WEBSITE_ID) . '"></script>' . "\n";
|
|
}
|
|
}, 1);
|
|
|
|
/** Organization + WebSite JSON-LD for trust/SEO. */
|
|
add_action('wp_head', static function (): void {
|
|
if (is_admin()) {
|
|
return;
|
|
}
|
|
$data = [
|
|
'@context' => 'https://schema.org',
|
|
'@graph' => [
|
|
[
|
|
'@type' => 'Organization',
|
|
'@id' => home_url('/#organization'),
|
|
'name' => 'Nomadro',
|
|
'url' => home_url('/'),
|
|
'email' => 'hello@nomadro.com',
|
|
'description' => 'Practical YouTube channel operations guides—production workflows, analytics, monetization, and creator team playbooks.',
|
|
],
|
|
[
|
|
'@type' => 'WebSite',
|
|
'@id' => home_url('/#website'),
|
|
'url' => home_url('/'),
|
|
'name' => 'Nomadro',
|
|
'publisher' => ['@id' => home_url('/#organization')],
|
|
'inLanguage' => 'en-US',
|
|
],
|
|
],
|
|
];
|
|
echo '<script type="application/ld+json">' . wp_json_encode($data, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE) . '</script>' . "\n";
|
|
}, 5);
|
|
|
|
/** Serve ads.txt from WordPress root reliably. */
|
|
add_action('init', static function (): void {
|
|
$uri = isset($_SERVER['REQUEST_URI']) ? strtok($_SERVER['REQUEST_URI'], '?') : '';
|
|
if ($uri === '/ads.txt') {
|
|
status_header(200);
|
|
header('Content-Type: text/plain; charset=utf-8');
|
|
header('X-Robots-Tag: noindex');
|
|
echo "google.com, pub-8461145959530971, DIRECT, f08c47fec0942fa0\n";
|
|
exit;
|
|
}
|
|
});
|
|
|
|
add_action('wp_enqueue_scripts', static function (): void {
|
|
wp_enqueue_style(
|
|
'nomadro-theme',
|
|
content_url('mu-plugins/nomadro-theme.css'),
|
|
[],
|
|
'2.1.0'
|
|
);
|
|
}, 30);
|
|
|
|
add_action('wp_body_open', static function (): void {
|
|
if (!is_front_page() && !is_home()) {
|
|
return;
|
|
}
|
|
echo '<section class="nomadro-hero" id="nomadro-hero"><div class="nomadro-hero-inner">';
|
|
echo '<div class="nomadro-kicker">YouTube operations</div>';
|
|
echo '<h1>Run a YouTube channel like an operator.</h1>';
|
|
echo '<p>Practical guides on production pipelines, analytics, monetization, and team workflows—written for creators who treat YouTube as a business.</p>';
|
|
echo '</div></section>';
|
|
});
|
|
|
|
add_action('wp_footer', static function (): void {
|
|
if (!is_front_page() && !is_home()) {
|
|
return;
|
|
}
|
|
echo '<script>document.addEventListener("DOMContentLoaded",function(){var h=document.getElementById("nomadro-hero");var b=document.querySelector(".wp-site-blocks");if(h&&b&&b.firstElementChild){b.insertBefore(h,b.firstElementChild.nextSibling);}});</script>';
|
|
}, 20);
|
|
|
|
/** Persistent trust links in footer (AdSense reviewers look for these). */
|
|
add_action('wp_footer', static function (): void {
|
|
$links = [
|
|
home_url('/about/') => 'About',
|
|
home_url('/contact/') => 'Contact',
|
|
home_url('/privacy-policy/') => 'Privacy Policy',
|
|
home_url('/terms/') => 'Terms of Service',
|
|
home_url('/disclaimer/') => 'Disclaimer',
|
|
];
|
|
echo '<nav class="nomadro-trust-footer" aria-label="Trust and policy links">';
|
|
foreach ($links as $url => $label) {
|
|
echo '<a href="' . esc_url($url) . '">' . esc_html($label) . '</a>';
|
|
}
|
|
echo '</nav>';
|
|
}, 5);
|
|
|
|
/** Harden & hygiene. */
|
|
remove_action('wp_head', 'wp_generator');
|
|
add_filter('the_generator', '__return_empty_string');
|
|
add_filter('xmlrpc_enabled', '__return_false');
|
|
|
|
/** Disable comments/pings by default for cleaner review surface. */
|
|
add_filter('comments_open', '__return_false', 20, 2);
|
|
add_filter('pings_open', '__return_false', 20, 2);
|
|
add_filter('comments_array', static function () {
|
|
return [];
|
|
}, 10, 2);
|
|
|
|
/** Better author label in bylines. */
|
|
add_filter('the_author', static function ($author) {
|
|
return 'Nomadro Editorial';
|
|
});
|
|
add_filter('get_the_author_display_name', static function () {
|
|
return 'Nomadro Editorial';
|
|
});
|