Open RadGH opened 5 years ago
Also yes, I can hide it with CSS and that's my current fallback. Problem is I still get notices that a term was deleted (that might be specific to yoast premium) because it's still technically active on the page.
Hi @RadGH , this is an option available for the user in the Yoast settings (SEO - Search Appearance - Taxonomies). But as I understand it, you want to disable the metabox yourself instead of letting the user do that. You can use the following to set the option that that settings page would normally set:
Call WPSEO_Options::set( 'display-metabox-tax-' . $taxonomy, false );
. $taxonomy has to be the name of your taxonomy in this case.
Does this provide the solution you're looking for? Please do note that the user will be able to enable the metabox themselves if they choose so via the aforementioned settings page.
@Djennez Yeah that looks like the same solution I was thinking to turn the option off in the admin. I suppose it's better than hiding it with CSS. But I was really hoping to disable yoast entirely for the taxonomy, without affecting the taxonomy functionality / visibility.
I'll use the code you provided, though I still think there should be a taxonomy equivalent of the post_type filter I mentioned.
Still got half way though, I guess! Thanks
@RadGH I thinkI am missing something, but what are you looking for to disable, in addition to the metabox? If you can explain that, maybe with a usecase, we can take that as feedback.
@Djennez I've got a few plugins that I would like to do this for and I've wondered about this before too. Right now I am working on a plugin that adds tests people can take. The tests are a post type called Exams. Exams show a set of random questions, not all of the questions are displayed. So I've got questions set as a taxonomy called Exam Questions. That makes it easy, if a question is used on the exam we just add it as a term to the exam post object..
Another plugin I would have wanted this for was for a search tool. We had a taxonomy that was purely for filtering results.
In both cases, the terms should not be "public". They don't have rewrites enabled. There is no term page. And even if you do use yoast to set a custom title / description, it would not be used anywhere. So it makes sense to disable it.
It's very similar to the post type for the Exams I mentioned. Those exams aren't going to show on Google either and are only visible to admins and the submitter. That was easily disabled with the filter in my original post.
Problem is there just isn't an equivalent for taxonomies. The classes Yoast uses to hook in to the taxonomy and add the metabox are all anonymous. So I can't just remove_filter/action there. That is unless I dig through $_wp_filters directly, but that's not very update-friendly at all.
Does that make sense?
Maybe this is too niche to bother with, but it just seemed like this would be very easy to add in without many side affects.
Allright, thanks! I will leave this thread open for product owners to look into this.
I stumbled on this topic while trying to hide the Yoast metabox for users with specific roles. As @RadGH mentions, the remove_meta_box
can be used for post types. An equivalent for terms is missing.
For now I was able to use the WPSEO_Options::set( 'display-metabox-tax-' . $taxonomy, false );
snippet provided by @Djennez, but I do think an apply_filters()
in term_metabox makes sense.
I tried using WPSEO_Options::set( 'display-metabox-tax-' . $taxonomy, false );
to remove the term metabox for my custom taxonomy attached to a CTP. Both the CTP and the custom taxonomy were registered on the init
hook. This method would work for the CTP, but not the taxonomy. Toggling the option on the WPSEO admin page under the Taxonomies tab would not save either. I was not able to figure out why.
I decided to look at the wpseo_title
option in the wp_options
table, the 'display-metabox-tax-' . $taxonomy
key was not in the array. My best guess is that WPSEO was removing it as an invalid option for some reason. Interestingly, I could run WPSEO_Options::set( 'noindex-tax-' . $taxonomy, true );
and that would save.
I eventually decided to hook into the option_wpseo_titles
filter, add the 'display-metabox-tax-' . $taxonomy
key set to false
. And that did the trick.
+1 for a filter
This would be a welcome option for me too. The bigger problem here is the fact that several Yoast classes are anonymous. I read that this is considered a bug in WordPress coding standards because you completely remove the ability to unhook actions.
Is your feature request related to a problem? Please describe.
No
Describe the solution you'd like
While
remove_meta_box( 'wpseo_meta', 'exam', 'normal')
works great for post types, there is no clean way to hide Yoast's metabox on a taxonomy in my plugin. Even a filter would work, just something to make my non-public taxonomy not show the Yoast metabox out of the box.why you think the feature request is something we should consider for the Yoast SEO plugins?
Because solutions like this Stack Overflow answer work great for post types, but there is no substitute for taxonomies.
Additional context
I would love to just unhook the action:
add_action( sanitize_text_field( $this->taxonomy ) . '_edit_form', array( $this, 'term_metabox' ), 90, 1 );
-- Unfortunately the class is anonymous so it requires significant hacky tactics to get around, or modifying the user's Yoast settings to disable it there.But even a simple solution would work like (class-taxonomy.php -> show_metabox):
if ( !apply_filters( 'yoast_display_taxonomy_metabox', true, $this->taxonomy ) ) return false;
Which would make it easy to disable the metabox inside of a plugin.