Joy
(@joyously)
That code should work for the archive page of the taxonomy, but not for anywhere else that the post is shown.
https://developer.wordpress.org/reference/functions/is_tax/
Thread Starter
mixali
(@mixali)
Thanks Joy,
Actually that is what I want, to apply the filter only on my custom taxonomy pages, but somehow it does nothing.
Joy
(@joyously)
Where did you put your code? The concern is order of execution.
Can you try it with an echo instead of a filter, just to see if it is matching?
Thread Starter
mixali
(@mixali)
That’s a good point Joy. I tried the echo instead of the filter but I do not get anything.
Instead, I tried too to use the conditional if ( is_singular( 'portfolio' ) )
but is not working, even if I’m pretty sure that this page post type is “portfolio”.
Any clue what is going in my portfolio?
Joy
(@joyously)
You didn’t answer “where did you put your code?”
If it’s straight in functions.php, that’s not going to work. If it’s in a function, when is that function run? If it’s in a template, that would affect only that template.
The query can’t match is_tax()
at the same time as is_singular()
since one is archive and one is single.
Thread Starter
mixali
(@mixali)
Thank you Joy,
As I said in my first message I am using this on functions.php file of my child theme, for example as:
function remove_empty_excerpt() {
if ( is_singular( 'portfolio' ) ) {
remove_filter( 'get_the_excerpt', 'wp_trim_excerpt' );
}
}
When I use there the following function:
add_action('wp_footer', 'your_function');
function your_function() {
$post_type = get_post_type( $post->ID );
echo $post_type;
}
I get the string “portfolio”, that is correct.
Am I missing a “add_action” on the first one? What should be the first argument?
Thanks in advance,
Thread Starter
mixali
(@mixali)
Thanks, Obviously I need a add_action but I am not sure what to use, i.e.
function remove_empty_excerpt() {
if ( is_singular( 'portfolio' ) ) {
remove_filter( 'get_the_excerpt', 'wp_trim_excerpt' );
}
}
add_filter( 'the_content', 'remove_empty_excerpt' );
This works definitively on my portfolio pages removing empty excerpts, but it will remove any content on any other post type.I need to ad an exception with an “else” for any other post type, right?
Joy
(@joyously)
Although actions and filters are “the same thing”, actions don’t return data but filters must return data. It’s not good to mix their usage.
Take a look at https://codex.wordpress.org/Plugin_API/Action_Reference and choose an action that allows the filter for excerpt to have been set up, but before the excerpt is output.