Remove Yoast fields programatically for a CPT
-
Hi
Is there any hook which allows to remove Yoast fields programatically?
Even it can be done in Yoast settings I would like to add this feature to a plugin I’m developing.Thanks
-
If you would like to remove the SEO settings from the Custom Post Type you’ve registered programmatically, you can do that by going to SEO > Search Appearance > Content Types(tab) where you’ll see the option to Toggle off the setting to disable the SEO metabox on the posts of Custom Post Type you have.
If this was not what you’re looking for, could you please explain which Yoast Settings would you like to remove for a CPT?
Hi
Yes, the new CPT “business” was created programatically but this is no the question.
What I meant is: since this CPT exists, I want to remove SEO settings for this CPT in the Add/Edit page of this CPT.
I know that I can enter SEO > Search Appearance > Content Types > Business (business) and set OFF the option “Show SEO settings for Business?”
But I want do it programatically.Why I do not want to enter Yoast Settings and do it as described?
Because I want to fire this option when my plugin is activated.
The user could forget to do it and I can save him time if the plugin do this task programatically.If is there any hook to do it, I would like to know what is.
Please, let me know if now is clear what I want to do or if I have to provide you more information.
Regards,
JairoHi @jairoochoa
Modifying the options in the Search Appearance menu is currently the only way to make sure the Yoast SEO meta box and settings don’t appear for your chosen CPT.
If you want to do this programmatically, you may have to refer to our developer portal for all documentation, should you want to modify the plugin output – https://developer.yoast.com/
Hello again @mikes41720,
I’ve found this code:
add_action( 'template_redirect', 'remove_wpseo' ); /** * Removes output from Yoast SEO on the frontend for a specific post, page or custom post type. */ function remove_wpseo() { if ( is_single ( 1 ) ) { $front_end = YoastSEO()->classes->get( Yoast\WP\SEO\Integrations\Front_End_Integration::class ); remove_action( 'wpseo_head', [ $front_end, 'present_head' ], -9999 ); } }This prevents Yoast’s fields be shown in the front, but fields would still be stored in the database.
What I want is not to modify plugin output. What I want is that these fields do not exist in the WP-admin so they won’t exist in the frontend.I will check developer portal again.
PS: This site has about 70,000 items of the CPT and I want to avoid that unnecessary data being stored in the database. 70,000 items are too many records and if Yoast adds a bunch of custom field per post, they are toooo many unnecessary records in the database.
Regards,
Jairo@jairoochoa Unfortunately we can’t offer support on custom code. Since we don’t want to take the risk that we break your website by suggesting incorrect or incomplete code, we cannot advise you on how to make such changes. Maybe someone watching these forums can assist you further, but if your topic is inactive for 7 days, we’ll mark it as resolved to keep the overview.
Thank you for your understanding.
Hi @devnihil
This is the question that started this topic:
Is there any hook which allows to remove Yoast fields programatically?
So, if there is no hook I will decide another way to do it.
Thanks
The topic ‘Remove Yoast fields programatically for a CPT’ is closed to new replies.