Making WordPress.org


Ignore:
Timestamp:
04/13/2020 10:56:06 PM (6 years ago)
Author:
coffee2code
Message:

Developer: More generally output meta tags (Open Graph, description, Twitter).

Previously only a meta description tag was output for singular parsed post types.

Props sebastienserre, coffee2code.
Fixes #4259.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-developer/functions.php

    r9646 r9715  
    77 */
    88require __DIR__ . '/inc/registrations.php';
     9
     10/**
     11 * HTML head tags and customizations.
     12 */
     13require __DIR__ . '/inc/head.php';
    914
    1015/**
    … …  
    416421
    417422/**
    418  * Output a <meta name="description" content=""> tag for Functions, Hooks, Classes and Methods.
    419  */
    420 function add_meta_description_for_summary() {
    421         if ( ! is_singular( array( 'wp-parser-function', 'wp-parser-hook', 'wp-parser-class', 'wp-parser-method' ) ) ) {
    422                 return;
    423         }
    424 
    425         $summary = wp_strip_all_tags( get_summary() );
    426 
    427         // Trim down to ~150 char based on full words.
    428         if ( strlen( $summary ) > 150 ) {
    429                 $words = preg_split( "/[\n\r\t ]+/", $summary, -1, PREG_SPLIT_NO_EMPTY );
    430 
    431                 $summary = '';
    432                 while ( $words ) {
    433                         $word = array_shift( $words );
    434                         if ( strlen( $summary ) + strlen( $word ) >= 141 ) { /* 150 - strlen( ' &hellip;' ) */
    435                                 break;
    436                         }
    437 
    438                         $summary .= $word . ' ';
    439                 }
    440 
    441                 if ( $words ) {
    442                         $summary .= '&hellip;';
    443                 }
    444         }
    445 
    446         if ( $summary ) {
    447                 printf( '<meta name="description" content="%s">' . "\n", esc_attr( $summary ) );
    448         }
    449 }
    450 add_action( 'wp_head', __NAMESPACE__ . '\add_meta_description_for_summary' );
    451 
    452 /**
    453423 * Outputs `<link rel="canonical">` tags where appropriate.
    454424 */
Note: See TracChangeset for help on using the changeset viewer.