K
K
Kvaesov2018-08-02 08:23:31
WordPress
Kvaesov, 2018-08-02 08:23:31

How to truncate Post Title in Wordpress to a specific character?

Hello. Tell me please.
On the main page of the site, the titles of the posts are displayed in the format:

Category - Title

That is, the name of the category is present in the title of the entry, and when displayed on the site, everything must be cut off before the Title.
The entry output code is as follows:
$title = get_the_title();
I tried to do this, but it doesn’t work, the entire title is cut off. You need to cut everything exactly to a space-dash-space, since just a dash can be present in the uncut part, but without spaces. Tell me how to do it right? I apologize if I explained a little chaotically.
$title = strstr(get_the_title(), ' - ');

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question