
/**
 * Plugin Name: YDSL RGB Solar Outdoor Lights — SEO Optimization
 * Description: Optimizes <title>, meta description, OG/Twitter tags, and H1 capitalization for /rgb-solar-outdoor-lights/ (post 7226).
 *              Title:       39 → 51 chars (adds wattage variants)
 *              Meta desc:   128 → 158 chars (adds IP67/remote/OEM keywords)
 *              H1:          fixes "rGB" → "RGB" capitalization typo
 *              Scoped to post 7226 only. Reversible by deactivating this plugin.
 * Version:     1.0.0
 * Author:      YDSL
 * Date:        2026-07-28
 */

if ( ! defined( 'ABSPATH' ) ) {
    exit;
}

const YDSL_RGB_SEO_POST_ID    = 7226;
const YDSL_RGB_SEO_TITLE      = 'RGB Solar Outdoor Lights 100W 200W 300W 400W | YDSL';
const YDSL_RGB_SEO_DESC       = 'YDSL RGB solar outdoor lights 100W/200W/300W/400W. IP67 waterproof color-changing lights with remote control for gardens, parks, villas. OEM/ODM available.';
const YDSL_RGB_SEO_H1_OLD     = '<h1 class="elementor-heading-title elementor-size-default">rGB outdoor lights Solar Powered</h1>';
const YDSL_RGB_SEO_H1_NEW     = '<h1 class="elementor-heading-title elementor-size-default">RGB Solar Outdoor Lights 100W 200W 300W 400W</h1>';

function ydsl_rgb_seo_should_apply() {
    if ( is_admin() ) {
        return false;
    }
    if ( ! is_singular( 'post' ) ) {
        return false;
    }
    return YDSL_RGB_SEO_POST_ID === (int) get_queried_object_id();
}

/* -------------------------------------------------------------------------
 * 1. <title> pipeline (pre_get_document_title wins over Yoast)
 * ---------------------------------------------------------------------- */
add_filter( 'pre_get_document_title', function( $title ) {
    return ydsl_rgb_seo_should_apply() ? YDSL_RGB_SEO_TITLE : $title;
}, 99 );

add_filter( 'wp_title', function( $title, $sep ) {
    return ydsl_rgb_seo_should_apply() ? YDSL_RGB_SEO_TITLE : $title;
}, 99, 2 );

/* -------------------------------------------------------------------------
 * 2. Yoast SEO title + Open Graph + Twitter Card titles
 * ---------------------------------------------------------------------- */
add_filter( 'wpseo_title', function( $title ) {
    return ydsl_rgb_seo_should_apply() ? YDSL_RGB_SEO_TITLE : $title;
}, 99 );

add_filter( 'wpseo_opengraph_title', function( $og_title ) {
    return ydsl_rgb_seo_should_apply() ? YDSL_RGB_SEO_TITLE : $og_title;
}, 99 );

add_filter( 'wpseo_twitter_title', function( $twitter_title ) {
    return ydsl_rgb_seo_should_apply() ? YDSL_RGB_SEO_TITLE : $twitter_title;
}, 99 );

/* -------------------------------------------------------------------------
 * 3. Yoast SEO meta description + OG + Twitter descriptions
 * ---------------------------------------------------------------------- */
add_filter( 'wpseo_metadesc', function( $description ) {
    return ydsl_rgb_seo_should_apply() ? YDSL_RGB_SEO_DESC : $description;
}, 99 );

add_filter( 'wpseo_opengraph_description', function( $og_desc ) {
    return ydsl_rgb_seo_should_apply() ? YDSL_RGB_SEO_DESC : $og_desc;
}, 99 );

add_filter( 'wpseo_twitter_description', function( $tw_desc ) {
    return ydsl_rgb_seo_should_apply() ? YDSL_RGB_SEO_DESC : $tw_desc;
}, 99 );

/* -------------------------------------------------------------------------
 * 4. H1 capitalization fix inside Elementor heading widget
 *    The H1 is rendered by Elementor, NOT via the_title()/the_content(),
 *    so we hook into elementor/widget/render_content and do a string replace
 *    that targets only the exact old markup on post 7226.
 * ---------------------------------------------------------------------- */
add_filter( 'elementor/widget/render_content', function( $html, $widget ) {
    if ( ! ydsl_rgb_seo_should_apply() ) {
        return $html;
    }
    return str_replace( YDSL_RGB_SEO_H1_OLD, YDSL_RGB_SEO_H1_NEW, $html );
}, 10, 2 );<?xml version="1.0" encoding="UTF-8"?><?xml-stylesheet type="text/xsl" href="//ydsolarlight.com/main-sitemap.xsl"?>
<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
	<sitemap>
		<loc>https://ydsolarlight.com/post-sitemap.xml</loc>
		<lastmod>2026-07-27T13:11:55+00:00</lastmod>
	</sitemap>
	<sitemap>
		<loc>https://ydsolarlight.com/page-sitemap.xml</loc>
		<lastmod>2026-07-26T12:10:49+00:00</lastmod>
	</sitemap>
</sitemapindex>
<!-- XML Sitemap generated by Rank Math SEO Plugin (c) Rank Math - rankmath.com -->