Hi @domeniko89,
Thanks for posting your question.
Secondary Title has a couple of filter hooks that allow you to filter where and how the secondary title will show up. In this case, it’s the filter get_secondary_title.
In that function, you’d have to check if the current post contains the category ID you’d like to have filtered out. You may also want to check if you’re on the Dashboard, otherwise, you won’t see the secondary title in the post overview.
Here’s a snippet that should work. I added a few comments, I hope this helps.
add_filter( "get_secondary_title", function ( string $secondary_title, int $post_id ) {
/** @var \WP_Post $post The original post */
$post = get_post( $post_id );
/** @var int $category_id The category ID (!) that should be filtered out */
$category_id = 1;
/** @var string $title Our new title */
$title = '';
/** If we're in the Dashboard or the filtered category ID isn't part of the post, show secondary title */
if ( is_admin() || ! in_array( $category_id, (array) $post->post_category ) ) {
$title = $secondary_title;
}
/** Otherwise, use the default title */
return (string) $title;
}, 10, 2 );
If it doesn’t help, please let me know. Also please note that this snippet just detects one category ID. However, checking for numerous category IDs is just a small adjustment.
Hi thank you very much for the answer I tried but unfortunately it doesn’t work for me, I’m not very familiar with php. Could you help me?
Did you change the $category_id
to the ID of the category you wanted to filter out?
Yes of course, I have inserted category instead of 1, with 103 the one that interests me. If you want I can pass you the accesses of the site so you can check it yourself thanks.
If I’ve earned your trust (as many other before you have, see the reviews section), I can take a manual look for you. Please send me the (S)TFP details to my email address which is kolja.nolte @
gmail.com.
This issue was resolved via email.
For anyone who might have the same problem, I can only give a temporary fix until the new version comes out.
Dear, I really appreciate the help provided. You solved a big problem that I’ve been looking for secondary solutions for the intent for quite a while. I sincerely thank you for your help. I am glad that with my question you have also improved your plugin and will release a new version.