I’m trying to do something similar to this question here: remove_action or remove_filter with external classes?
I’m trying to remove the
<!-- This site is optimized with the Yoast WordPress SEO plugin v1.0.3 - http;//yoast.com/wordpress/seo/ -->
message from the plugin.
And before you yell at me about how this may be unethical the author says it’s okay to do here: http://wordpress.org/support/topic/plugin-wordpress-seo-by-yoast-how-to-remove-dangerous-inserted-yoast-message-in-page-headers?replies=29#post-2503475
I have found the class that adds the comment here: http://plugins.svn.wordpress.org/wordpress-seo/tags/1.2.8.7/frontend/class-frontend.php
Basically the WPSEO_Frontend
class has a function named debug_marker
which is then called by a function named head
which is then added to wp_head
in __Construct
I’m new to classes but I found a way to completely remove the head by doing
global $wpseo_front;
remove_action( 'wp_head', array($wpseo_front,'head'), 1, 1 );
but I only want to remove the debug_marker
part from it. I tried this but it dosen’t work
remove_action( 'wp_head', array($wpseo_front,'head','debug_marker'), 1, 1 );
As I said I’m new to classes so any help would be great.
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 thewp_head()
call withob_start($cb)
andob_end_flush();
functions like:Now in theme
functions.php
file, declare your output callback function (ad_filter_wp_head_output
in this case):If you want to do all that through the
functions.php
without editingheader.php
file, you can hook toget_header
andwp_head
action hooks to define the output buffering session:Thanks for all your help, i finally resolved it.
I created a functions.php for my child theme, then add
I don’t think you are going to be able to do that using
remove_action
. The function argument inremove_action
will not help you as thedebug_marker()
function was not the function that was used in theadd_action()
call.Yoast presumably has something like
add_action( "wp_head", "head" )
in his code. So you can remove the “head” function, butdebug_marker
was not explicitly added as an action.You could
WPSEO_Frontend
class and overload thedebug_marker
function to return “”. TBH, I’m not sure how this would work in terms of WP loading the plugin, but could be worth investigating.Finding this thread after working on the same solution as the one mentioned by
Steve Claridge
, that is:Extend the
WPSEO_Frontend
class and overload thedebug_marker
function to return “”I detailed the steps below, although I’m getting stuck in the final step.
Create a customization plugin
As mentioned in this article from WP Tavern, “the easiest way to accomplish this is to create a functionality plugin that will run alongside it”.
So I went on to creating my first plugin following this article from ElegantTheme.
Extend the relevant class.
That’s when things got complicated. I added the following but my overriding function is still not triggered for some reason.
I’ve found that you can remove the debug_marker action in functions.php.
Yoast plugin is executed in the wp_head action. I just took the action hook which follows directly after that, namely wp_enqueue_scripts and there I hooked a function that removed the debug_marker output. For this you also have to pass the plugin object. Also the priority number has to be the same as the one set from within the plugin.
However this does not remove the
part, because that is echoed in the plugin’s crucial wrapper function head.
You could try overwriting that.
To add to Ahmad’s answer you could just remove all html comments with the same amount of code, since Yoast isn’t the only plugin that does that.
I’ve came across a snippet that removes all Yoast WordPress SEO comments from the front end. It also modifies the output buffering approach that @bryan-willis and @ahmad-m’s answers use.
Simply place the snippet on your theme’s
functions.php
or a custom plugin/theme php file.I’ll leave it here as a reference – credit goes to the snippet’s author
This is a modified version of @ahmad-m Answer, by applying filters you can make multiple content changes to the header html .
Found a similar solution for
functions.php
which does not use hardcoded priority2
but dynamically reads and uses the priority from Yoastadd_action()
.See flush_cache function in wordpress-seo/frontend/class-frontend.php
Find this line of code
Replace with
Thanks to the creator of this great plugin.