Skip to main content
added 38 characters in body
Source Link
Ahmad M
  • 2.7k
  • 2
  • 21
  • 19

A simple way to doachieve this (but without the Class approach) is by filtering the output of wp_head action hook using the output buffering.

In your theme's header.php, wrap the wp_head() call with ob_start($cb) and ob_end_flush(); functions like:

ob_start('ad_filter_wp_head_output'); wp_head(); ob_end_flush(); 

Now in theme functions.php file, declare your output callback function (ad_filter_wp_head_output in this case):

function ad_filter_wp_head_output($output) { if (defined('WPSEO_VERSION')) { $output = str_ireplace('<!-- This site is optimized with the Yoast WordPress SEO plugin v' . WPSEO_VERSION . ' - http://yoast.com/wordpress/seo/ -->', '', $output); $output = str_ireplace('<!-- / Yoast WordPress SEO plugin. -->', '', $output); } return $output; } 

If you want to do all that through the functions.php without editing header.php file, you can hook to get_header and wp_head action hooks to define the output buffering session:

add_action('get_header', 'ad_ob_start'); add_action('wp_head', 'ad_ob_end_flush', 100); function ad_ob_start() { ob_start('ad_filter_wp_head_output'); } function ad_ob_end_flush() { ob_end_flush(); } function ad_filter_wp_head_output($output) { if (defined('WPSEO_VERSION')) { $output = str_ireplace('<!-- This site is optimized with the Yoast WordPress SEO plugin v' . WPSEO_VERSION . ' - http://yoast.com/wordpress/seo/ -->', '', $output); $output = str_ireplace('<!-- / Yoast WordPress SEO plugin. -->', '', $output); } return $output; } 

A simple way to do this is by filtering the output of wp_head action hook using the output buffering.

In your theme's header.php, wrap the wp_head() call with ob_start($cb) and ob_end_flush(); functions like:

ob_start('ad_filter_wp_head_output'); wp_head(); ob_end_flush(); 

Now in theme functions.php file, declare your output callback function (ad_filter_wp_head_output in this case):

function ad_filter_wp_head_output($output) { if (defined('WPSEO_VERSION')) { $output = str_ireplace('<!-- This site is optimized with the Yoast WordPress SEO plugin v' . WPSEO_VERSION . ' - http://yoast.com/wordpress/seo/ -->', '', $output); $output = str_ireplace('<!-- / Yoast WordPress SEO plugin. -->', '', $output); } return $output; } 

If you want to do all that through the functions.php without editing header.php file, you can hook to get_header and wp_head action hooks to define the output buffering session:

add_action('get_header', 'ad_ob_start'); add_action('wp_head', 'ad_ob_end_flush', 100); function ad_ob_start() { ob_start('ad_filter_wp_head_output'); } function ad_ob_end_flush() { ob_end_flush(); } function ad_filter_wp_head_output($output) { if (defined('WPSEO_VERSION')) { $output = str_ireplace('<!-- This site is optimized with the Yoast WordPress SEO plugin v' . WPSEO_VERSION . ' - http://yoast.com/wordpress/seo/ -->', '', $output); $output = str_ireplace('<!-- / Yoast WordPress SEO plugin. -->', '', $output); } return $output; } 

A simple way to achieve this (but without the Class approach) is by filtering the output of wp_head action hook using the output buffering.

In your theme's header.php, wrap the wp_head() call with ob_start($cb) and ob_end_flush(); functions like:

ob_start('ad_filter_wp_head_output'); wp_head(); ob_end_flush(); 

Now in theme functions.php file, declare your output callback function (ad_filter_wp_head_output in this case):

function ad_filter_wp_head_output($output) { if (defined('WPSEO_VERSION')) { $output = str_ireplace('<!-- This site is optimized with the Yoast WordPress SEO plugin v' . WPSEO_VERSION . ' - http://yoast.com/wordpress/seo/ -->', '', $output); $output = str_ireplace('<!-- / Yoast WordPress SEO plugin. -->', '', $output); } return $output; } 

If you want to do all that through the functions.php without editing header.php file, you can hook to get_header and wp_head action hooks to define the output buffering session:

add_action('get_header', 'ad_ob_start'); add_action('wp_head', 'ad_ob_end_flush', 100); function ad_ob_start() { ob_start('ad_filter_wp_head_output'); } function ad_ob_end_flush() { ob_end_flush(); } function ad_filter_wp_head_output($output) { if (defined('WPSEO_VERSION')) { $output = str_ireplace('<!-- This site is optimized with the Yoast WordPress SEO plugin v' . WPSEO_VERSION . ' - http://yoast.com/wordpress/seo/ -->', '', $output); $output = str_ireplace('<!-- / Yoast WordPress SEO plugin. -->', '', $output); } return $output; } 
Source Link
Ahmad M
  • 2.7k
  • 2
  • 21
  • 19

A simple way to do this is by filtering the output of wp_head action hook using the output buffering.

In your theme's header.php, wrap the wp_head() call with ob_start($cb) and ob_end_flush(); functions like:

ob_start('ad_filter_wp_head_output'); wp_head(); ob_end_flush(); 

Now in theme functions.php file, declare your output callback function (ad_filter_wp_head_output in this case):

function ad_filter_wp_head_output($output) { if (defined('WPSEO_VERSION')) { $output = str_ireplace('<!-- This site is optimized with the Yoast WordPress SEO plugin v' . WPSEO_VERSION . ' - http://yoast.com/wordpress/seo/ -->', '', $output); $output = str_ireplace('<!-- / Yoast WordPress SEO plugin. -->', '', $output); } return $output; } 

If you want to do all that through the functions.php without editing header.php file, you can hook to get_header and wp_head action hooks to define the output buffering session:

add_action('get_header', 'ad_ob_start'); add_action('wp_head', 'ad_ob_end_flush', 100); function ad_ob_start() { ob_start('ad_filter_wp_head_output'); } function ad_ob_end_flush() { ob_end_flush(); } function ad_filter_wp_head_output($output) { if (defined('WPSEO_VERSION')) { $output = str_ireplace('<!-- This site is optimized with the Yoast WordPress SEO plugin v' . WPSEO_VERSION . ' - http://yoast.com/wordpress/seo/ -->', '', $output); $output = str_ireplace('<!-- / Yoast WordPress SEO plugin. -->', '', $output); } return $output; }