Advertisement
s2prod

Supprimer les commentaires de Yoast SEO dans le code source

Mar 18th, 2017
417
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.04 KB | None | 0 0
  1. //A ajouter dans le fichier functions.php de votre thème
  2. //Add this to your theme functions.php file
  3.  
  4. /* Supprime les commentaires de Yoast SEO dans le code source */
  5. /* Remove Yoast SEO comments in source code */
  6.  
  7.  
  8. if ( ! defined( 'ABSPATH' ) ) { exit; }
  9.  
  10. function rysc_bundle() {
  11.     if(defined( 'WPSEO_VERSION' ) && class_exists('WPSEO_Frontend')) {
  12.         remove_action( 'wpseo_head', array( WPSEO_Frontend::get_instance(), 'debug_mark' ) , 2);
  13.         remove_action( 'wp_head', array( WPSEO_Frontend::get_instance(), 'head' ) , 1);
  14.         add_action( 'wp_head', 'rysc_rewrite' , 1);
  15.     }
  16. }
  17. add_action( 'init', 'rysc_bundle' );
  18.  
  19. function rysc_rewrite() {
  20.     $rewrite = new ReflectionMethod( 'WPSEO_Frontend', 'head' );
  21.  
  22.     $filename = $rewrite->getFileName();
  23.     $start_line = $rewrite->getStartLine();
  24.     $end_line = $rewrite->getEndLine()-1;
  25.    
  26.     $length = $end_line - $start_line;
  27.     $source = file($filename);
  28.     $body = implode("", array_slice($source, $start_line, $length));
  29.     $body = preg_replace( '/echo \'\<\!(.*?)\n/', '', $body);
  30.    
  31.     eval($body);
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement