158 lines
5.4 KiB
PHP
158 lines
5.4 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="#ffffff">' . "\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 digital nomad guides for remote work, travel systems, and location-independent income.',
|
|
],
|
|
[
|
|
'@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;
|
|
}
|
|
});
|
|
|
|
/** Editorial CSS: readable articles, image presentation, footer trust links. */
|
|
add_action('wp_enqueue_scripts', static function (): void {
|
|
$css = <<<'CSS'
|
|
:root { --nomadro-accent:#6d28d9; }
|
|
body { -webkit-font-smoothing: antialiased; }
|
|
.nomadro-hero-figure img,
|
|
.wp-block-post-featured-image img,
|
|
.wp-post-image {
|
|
border-radius: 14px;
|
|
width: 100%;
|
|
height: auto;
|
|
}
|
|
.nomadro-hero-figure figcaption,
|
|
figure.wp-block-image figcaption {
|
|
color: #667085;
|
|
font-size: 0.92rem;
|
|
margin-top: 0.5rem;
|
|
}
|
|
.nomadro-callout {
|
|
border-left: 4px solid var(--nomadro-accent) !important;
|
|
background: #f5f3ff !important;
|
|
border-radius: 8px;
|
|
padding: 14px 18px !important;
|
|
margin: 1.5rem 0 !important;
|
|
}
|
|
.entry-content, .wp-block-post-content {
|
|
font-size: 1.0625rem;
|
|
line-height: 1.75;
|
|
}
|
|
.entry-content h2, .wp-block-post-content h2 {
|
|
margin-top: 2rem;
|
|
line-height: 1.3;
|
|
}
|
|
.wp-block-post-excerpt, .entry-summary {
|
|
color: #475467;
|
|
}
|
|
.nomadro-trust-footer {
|
|
display: flex;
|
|
flex-wrap: wrap;
|
|
gap: 0.75rem 1.25rem;
|
|
justify-content: center;
|
|
padding: 1.5rem 1rem 2rem;
|
|
font-size: 0.95rem;
|
|
}
|
|
.nomadro-trust-footer a { color: #344054; text-decoration: underline; }
|
|
CSS;
|
|
wp_register_style('nomadro-adsense-opt', false, [], '1.0.0');
|
|
wp_enqueue_style('nomadro-adsense-opt');
|
|
wp_add_inline_style('nomadro-adsense-opt', $css);
|
|
}, 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';
|
|
});
|