add_action pre_term_description vs. pre_category_description

I am trying to set a default tag and a (different) default category description in case there is none given on creation.

I have found the action “pre_category_description”, but no equivalent for the tags. The only thing that I could find is “pre_term_description”, but that one behaves weird.

I have added the following code to my plugin:

add_action(‘pre_term_description’, ‘default_term’);
function default_term($description) {
if ($description == ”){
$description_new = “default term description”;
} else {
$description_new = $description;
}
error_log(“setting term description”);
return $description_new;
}

add_action(‘pre_category_description’, ‘default_category’);
function default_category($description) {
if ($description == ”){ // we only replace in case there is a setting and no input
$description_new = “default category description”;
} else {
$description_new = $description;
}
error_log(“setting category description”);
return $description_new;
}

However, it seems that pre_term description is being executed for both tags AND categories, and the term description overrules the category one, although it’s executed last.

If I add a new tag, I get this log entry:

[06-Dec-2018 07:44:54 UTC] setting term description

and the resulting description is “default term description”

if I add a new category, I get this here:

[06-Dec-2018 07:44:54 UTC] setting term description
[06-Dec-2018 07:44:54 UTC] setting category description

and the resulting description is ALSO “default term description”

How can I make a differentiation if the edited item is a category or a tag so that this works properly?

Read more here:: add_action pre_term_description vs. pre_category_description

Leave a Reply

Your email address will not be published. Required fields are marked *