Plugin Directory

Changeset 3458320


Ignore:
Timestamp:
02/10/2026 06:01:59 PM (7 weeks ago)
Author:
butterflymedia
Message:

Change excerpt generation from 55 words to 155 characters for proper SEO meta description length and add sanitization and removal of non-breaking spaces ( ) from meta descriptions

Location:
wp-perfect-plugin/trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • wp-perfect-plugin/trunk/includes/functions.php

    r3441000 r3458320  
    167167
    168168        // Cache function_exists() results to avoid repeated checks
    169         static $has_edd = null;
    170         static $has_wc = null;
     169        static $has_edd  = null;
     170        static $has_wc   = null;
    171171        static $has_mepr = null;
    172172
     
    279279
    280280    // Fallback: Generate excerpt from content (only if excerpt is empty)
    281     // Use wp_trim_words() directly on post_content for better performance
    282     $content = $post->post_content;
    283     $content = strip_shortcodes( $content );
    284     $content = wp_strip_all_tags( $content );
    285     $excerpt = wp_trim_words( $content, 55, '...' );
     281    // Use character limit (155) instead of word count for SEO meta descriptions
     282    $content = strip_shortcodes( $post->post_content );
     283    $content = sanitize_text_field( $content );
     284    $content = str_replace( [ ' ', "\xC2\xA0" ], ' ', $content ); // Remove   entities and UTF-8 non-breaking spaces
     285
     286    // Trim to 155 characters (recommended meta description length)
     287    if ( mb_strlen( $content ) > 155 ) {
     288        $excerpt = mb_substr( $content, 0, 155 ) . '...';
     289    } else {
     290        $excerpt = $content;
     291    }
    286292
    287293    return esc_attr( $excerpt );
     
    349355                // For categories, use the current URL to preserve custom URL structures
    350356                // This handles cases where categories are siblings or have custom permalink structures
    351                 $request_uri = isset( $_SERVER['REQUEST_URI'] ) ? $_SERVER['REQUEST_URI'] : '';
    352                 $current_url = home_url( $request_uri );
     357                $request_uri   = isset( $_SERVER['REQUEST_URI'] ) ? $_SERVER['REQUEST_URI'] : '';
     358                $current_url   = home_url( $request_uri );
    353359                $canonical_url = strtok( $current_url, '?' ); // Remove query parameters
    354360            } else {
     
    358364            // Fallback: if the term link fails, use the current URL without query parameters
    359365            if ( is_wp_error( $canonical_url ) ) {
    360                 $request_uri = isset( $_SERVER['REQUEST_URI'] ) ? $_SERVER['REQUEST_URI'] : '';
    361                 $current_url = home_url( $request_uri );
     366                $request_uri   = isset( $_SERVER['REQUEST_URI'] ) ? $_SERVER['REQUEST_URI'] : '';
     367                $current_url   = home_url( $request_uri );
    362368                $canonical_url = strtok( $current_url, '?' ); // Remove query parameters
    363369            }
     
    375381            $canonical_url = get_year_link( $year );
    376382        } elseif ( is_month() ) {
    377             $monthnum = get_query_var( 'monthnum' );
     383            $monthnum      = get_query_var( 'monthnum' );
    378384            $canonical_url = get_month_link( $year, $monthnum );
    379385        } elseif ( is_day() ) {
    380             $monthnum = get_query_var( 'monthnum' );
    381             $day = get_query_var( 'day' );
     386            $monthnum      = get_query_var( 'monthnum' );
     387            $day           = get_query_var( 'day' );
    382388            $canonical_url = get_day_link( $year, $monthnum, $day );
    383389        }
     
    435441    if ( $w3p_kg_logo ) {
    436442        // Transient key based on logo URL hash
    437         $transient_key = 'w3p_kg_logo_dimensions_' . md5( $w3p_kg_logo );
     443        $transient_key     = 'w3p_kg_logo_dimensions_' . md5( $w3p_kg_logo );
    438444        $cached_dimensions = get_transient( $transient_key );
    439        
     445
    440446        if ( false !== $cached_dimensions ) {
    441447            // Use cached dimensions
     
    445451            // Try to get attachment ID from URL (expensive query - cache the result)
    446452            $attachment_id_transient_key = 'w3p_kg_logo_attachment_id_' . md5( $w3p_kg_logo );
    447             $attachment_id = get_transient( $attachment_id_transient_key );
    448            
     453            $attachment_id               = get_transient( $attachment_id_transient_key );
     454
    449455            if ( false === $attachment_id ) {
    450456                // Only call attachment_url_to_postid if not in transient (expensive query)
     
    453459                set_transient( $attachment_id_transient_key, $attachment_id, WEEK_IN_SECONDS );
    454460            }
    455            
     461
    456462            if ( $attachment_id ) {
    457463                // Get dimensions from attachment metadata (stored in database)
     
    462468                }
    463469            }
    464            
     470
    465471            // Cache dimensions for 7 days
    466             set_transient( $transient_key, [
    467                 'width'  => $w3p_kg_logo_width,
    468                 'height' => $w3p_kg_logo_height,
    469             ], WEEK_IN_SECONDS );
     472            set_transient(
     473                $transient_key,
     474                [
     475                    'width'  => $w3p_kg_logo_width,
     476                    'height' => $w3p_kg_logo_height,
     477                ],
     478                WEEK_IN_SECONDS
     479            );
    470480        }
    471481    }
  • wp-perfect-plugin/trunk/readme.txt

    r3441000 r3458320  
    44Requires at least: 5.7
    55Requires PHP: 7.1
    6 Tested up to: 6.9
    7 Stable tag: 2.1.1
     6Tested up to: 6.9.1
     7Stable tag: 2.1.2
    88License: GPLv3 or later
    99License URI: https://www.gnu.org/licenses/gpl-3.0.html
     
    3333
    3434== Changelog =
     35
     36= 2.1.2 =
     37* FIX: Change excerpt generation from 55 words to 155 characters for proper SEO meta description length
     38* FIX: Add sanitization and removal of non-breaking spaces ( ) from meta descriptions
    3539
    3640= 2.1.1 =
  • wp-perfect-plugin/trunk/wp-perfect-plugin.php

    r3441000 r3458320  
    66 * Author: Ciprian Popescu
    77 * Author URI: https://getbutterfly.com/
    8  * Version: 2.1.1
     8 * Version: 2.1.2
    99 * License: GNU General Public License v3 or later
    1010 * License URI: https://www.gnu.org/licenses/gpl-3.0.html
     
    3535define( 'W3P_URL', WP_PLUGIN_URL . '/' . dirname( plugin_basename( __FILE__ ) ) );
    3636define( 'W3P_PATH', plugin_dir_path( __FILE__ ) );
    37 define( 'W3P_VERSION', '2.1.1' );
     37define( 'W3P_VERSION', '2.1.2' );
    3838
    3939require 'includes/functions.php';
Note: See TracChangeset for help on using the changeset viewer.