Another way to approach this would be to standardize the different elements by passing them to a common included template with the same variable
For entry pages:
{% if entry is defined %}
{% include '_partials/meta' with {
element: entry
} %}
{% endif %}
For category pages:
{% if category is defined %}
{% include '_partials/meta' with {
element: category
} %}
{% endif %}
Now you can use the common element
variable to output any values. This would be easiest if you also used the same seo fields (title, description, etc.) on all of the different Elements you wanted to support SEO for:
{# _partials/meta #}
<title>{{ element.title }}</title>
<meta name="description" content="{{ element.description }}">