/** * TEC — one-time US English spelling fix for the 29 location pages * flagged in the Communities audit (Oct 19, 2026). * * Paste into Code Snippets or WPCode as a PHP snippet (not Elementor Custom Code). * Run it while logged in as an admin: * 1. Preview: https://theexteriorscompany.com/wp-admin/?tec_us_spelling=preview * 2. Click "Apply these changes" at the bottom of the preview. * 3. Purge page cache / Cloudflare, then deactivate and delete this snippet. * * Only edits the Elementor content (_elementor_data) and post_content of the * page IDs listed below. Take a database backup before applying. */ add_action( 'admin_init', 'tec_us_spelling_run' ); function tec_us_spelling_pages() { return array( 3851 => '/emergency-exterior-company/sun-prairie-wi-emergency-roof-repair/', 3891 => '/emergency-exterior-company/middleton-wi-emergency-roof-repair/', 3930 => '/windows/verona-wi-windows/', 3931 => '/siding/verona-wi-siding/', 3934 => '/emergency-exterior-company/verona-wi-emergency-roof-repair/', 3935 => '/communities/verona-wi-exterior-company/', 4345 => '/windows/fitchburg-wi-windows/', 4346 => '/siding/fitchburg-wi-siding/', 4351 => '/emergency-exterior-company/fitchburg-wi-emergency-roof-repair/', 4353 => '/roofing/fitchburg-wi-roofing/', 4628 => '/roofing/waunakee-wi-roofing/', 4629 => '/windows/waunakee-wi-windows/', 4631 => '/gutters/waunakee-wi-gutters/', 4633 => '/emergency-exterior-company/waunakee-wi-emergency-roof-repair/', 4679 => '/gutters/stoughton-wi-gutters/', 4680 => '/storm-damage/stoughton-wi-storm-damage/', 4681 => '/emergency-exterior-company/stoughton-wi-emergency-roof-repair/', 4717 => '/siding/cottage-grove-wi-siding/', 4983 => '/windows/evansville-wi-windows/', 4984 => '/siding/evansville-wi-siding/', 4985 => '/gutters/evansville-wi-gutters/', 4986 => '/storm-damage/evansville-wi-storm-damage/', 4987 => '/emergency-exterior-company/evansville-wi-emergency-roof-repair/', 4988 => '/communities/evansville-wi-exterior-company/', 5021 => '/roofing/deforest-wi-roofing/', 5022 => '/windows/deforest-wi-windows/', 5023 => '/siding/deforest-wi-siding/', 5026 => '/emergency-exterior-company/deforest-wi-emergency-roof-repair/', 5027 => '/communities/deforest-wi-exterior-company/', ); } function tec_us_spelling_rules() { // Word start that also works inside Elementor's JSON (after \n or a “ curly quote). $start = '(?:(? 'color', 'neighbour' => 'neighbor', 'aluminium' => 'aluminum', 'draught' => 'draft', 'fibreglass' => 'fiberglass', 'stabilis' => 'stabiliz', 'prioritis' => 'prioritiz', 'mobilis' => 'mobiliz', 'itemis' => 'itemiz', 'honour' => 'honor', 'favourite' => 'favorite', ); // Whole words only, where a stem swap would be wrong. $words = array( 'centred' => 'centered', 'centres' => 'centers', 'centre' => 'center', 'cheques' => 'checks', 'cheque' => 'check', ); $rules = array(); foreach ( $stems as $uk => $us ) { $rules[ '/' . $start . '(' . $uk . ')/i' ] = $us; } foreach ( $words as $uk => $us ) { $rules[ '/' . $start . '(' . $uk . ')(?![A-Za-z])/i' ] = $us; } return $rules; } // Replace while keeping capitalization: colour > color, Colour > Color, COLOUR > COLOR. function tec_us_spelling_fix( $text, $rules, &$hits ) { foreach ( $rules as $pattern => $us ) { $text = preg_replace_callback( $pattern, function ( $m ) use ( $us, &$hits ) { $found = $m[1]; $hits[] = strtolower( $found ); if ( strtoupper( $found ) === $found ) { return strtoupper( $us ); } if ( ctype_upper( $found[0] ) ) { return ucfirst( $us ); } return $us; }, $text ); } return $text; } function tec_us_spelling_run() { if ( empty( $_GET['tec_us_spelling'] ) || ! current_user_can( 'manage_options' ) ) { return; } $apply = ( 'apply' === $_GET['tec_us_spelling'] ); if ( $apply ) { check_admin_referer( 'tec_us_spelling_apply' ); } global $wpdb; $rules = tec_us_spelling_rules(); $rows = array(); $total = 0; foreach ( tec_us_spelling_pages() as $id => $path ) { $post = get_post( $id ); if ( ! $post ) { $rows[] = array( $id, $path, 0, 'Page not found, skipped' ); continue; } $hits = array(); $data = get_post_meta( $id, '_elementor_data', true ); $new_data = ( is_string( $data ) && '' !== $data ) ? tec_us_spelling_fix( $data, $rules, $hits ) : $data; $content = $post->post_content; $new_content = tec_us_spelling_fix( $content, $rules, $hits ); $count = count( $hits ); $total += $count; $parts = array(); foreach ( array_count_values( $hits ) as $word => $n ) { $parts[] = ( $n > 1 ) ? $word . ' x' . $n : $word; } $rows[] = array( $id, $path, $count, $parts ? implode( ', ', $parts ) : 'Nothing found' ); if ( $apply && $count ) { if ( $new_data !== $data ) { update_post_meta( $id, '_elementor_data', wp_slash( $new_data ) ); } if ( $new_content !== $content ) { $wpdb->update( $wpdb->posts, array( 'post_content' => $new_content ), array( 'ID' => $id ) ); } clean_post_cache( $id ); } } if ( $apply && class_exists( '\Elementor\Plugin' ) ) { \Elementor\Plugin::$instance->files_manager->clear_cache(); } // Report page $title = $apply ? 'Spelling fixes applied' : 'Spelling fix preview (nothing changed yet)'; $html = '
' . esc_html( ( $apply ? 'Replaced ' : 'Will replace ' ) . $total . ' occurrences across ' . count( $rows ) . ' pages. Counts include Elementor data and the page copy, so most words appear twice.' ) . '
'; $html .= '| ID | Page | Count | Words |
|---|---|---|---|
| ' . esc_html( $r[0] ) . ' | ' . esc_html( $r[1] ) . ' | ' . esc_html( $r[2] ) . ' | ' . esc_html( $r[3] ) . ' |
Done. Elementor CSS cache cleared. Purge your page cache and Cloudflare, then deactivate and delete this snippet.
'; } else { $url = wp_nonce_url( admin_url( '?tec_us_spelling=apply' ), 'tec_us_spelling_apply' ); $html .= ''; } wp_die( $html, esc_html( $title ), array( 'response' => 200 ) ); } Skip to content