I am working on a custom post type and I don't want it to get all the clutter from wp_head(). However, I do want to show a specific hook, for example the YoastSEO meta tags.

How do I call a specific single hook in the template file without wp_head()? I tried adding a filter to wp_head that removes the parts I don't want, e.g.:

if ( 'customtype' === get_post_type() )
      remove_action( 'wp_head', 'rsd_link' );
      remove_action( 'wp_head', 'feed_links' );
      remove_action( 'wp_head', 'wlwmanifest_link' );
      remove_action( 'wp_head', 'wp_generator' );
      remove_action( 'wp_head', 'start_post_rel_link' );
      remove_action( 'wp_head', 'index_rel_link' );
      remove_action( 'wp_head', 'adjacent_posts_rel_link' );
      remove_action( 'wp_head', 'wp_shortlink_wp_head' );

However, this seems inefficient and I would have to maintain any additional plugins or functions that manipulate or add actions to wp_head().

Is there a way to remove ALL actions and keep the one(s) I want? I'd prefer not including wp_head at all and just call whatever action I need for that custom post type.

  • 1
    @TimMalone, you can take a broader view of the question ;) - how to disable all action hooks except for one Commented May 4, 2016 at 8:38
  • I do not see the use of this all. Blindly removing actions from wp_head, or removing wp_head() completely is stupid and suicidle. This will break a huge amount of other things which I can gaurentee you you will come back to ask questions about. wp_head() is as important as to an engine to a car Commented May 4, 2016 at 10:43
  • @PieterGoosen Please read the question again.
    – kaiser
    Commented May 5, 2016 at 0:24

2 Answers 2


wp_head is an essential part of the theme, and there is too many things that might fall apart if it is not there. Hunting and fixing them one by one might be time consuming and the worthiness of the all operation questionable.

In you snippet for example you want to remove things that make no sense to remove specifically only for one CPT, and if you have them on other post types there is no real reason not to have them on that one.

  • Fair enough, however, to give you a clearer idea, the CPT is for campaigns/ladning pages, meaning I want the pages to be minimal, feeds are irrelevant, plugins are irrelevant, enqueued styles and scripts are irrelevant since I will be adding custom ones - this is for a controlled theme. What essential parts are in wp_head that can really break the theme?
    – Aziz
    Commented May 4, 2016 at 8:46
  • 1
    @aziz, excluding what you do not need is IMO a much more clearer path then the other direction. as you explicitly know what might have been there and you have excluded, than guessing, in case of anything going wrong, if it is something that should have been there but isn't Commented May 4, 2016 at 11:08
  • All right, point taken. Is there an easy way to list all called hooks so that I can exclude what I don't want instead of searching for their names for hours?
    – Aziz
    Commented May 4, 2016 at 11:12
  • @Aziz, as for thos specific fields (or anything else in the head section, I believe thta only people with OCD will look at the page source, and no one is likely to understand what they are in any case Commented May 4, 2016 at 11:13
  • good question, that might already have an answer ;) I would guess there is a plugin that can do that Commented May 4, 2016 at 11:14

Since plugins hook directly into wp_head nothing will happen if it's not there unless you change the plugin code. So, you'd have to create your own hook in the theme, then scan the Yoast files for any calls to wp_head and change them. Not recommended, though.

A better course of action would be to generate these metatags yourself. They're pretty straightforward.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.