Hi i was wondering if there is a way that i can display the custom post type title.
For example:
I have a custom post type entitled “Pretty Little Liars” and it also shows on the homepage, but how do i get the POST TYPE title, not the title of the post to show up like a category.
For example:
Plublished in: Pretty Little Liars
is this possible?
Also i want it to link to the post type page
You can write a general template tag for this task.
Explanation
We got two variables declared as
static
, so we don’t have to redo the task, if you’re for example using it inside a loop that shows posts from different post types.You also got an argument (
(bool) true/false
) to switch if you just want to return or right print the name.This function doesn’t work for built in post types (assuming you don’t need it). If you need it for built in post types too, then just remove the
_builtin
argument from the function inside âget_post_types()
.Just in case someone is looking for further answers here, there is a builtin wordpress function:
its there since 2011, reference: https://developer.wordpress.org/reference/functions/post_type_archive_title/, old reference: https://codex.wordpress.org/Function_Reference/post_type_archive_title