Recommended Free Tools
For a shorter post title in a WordPress template, retrieve it with get_the_title(), trim it with wp_trim_words(), then escape it for the HTML context where it appears. This limits the displayed version without changing the stored post title.
Trim a title to a word limit in a template
Use this where the title is rendered, such as a post card or archive listing:
<?php
$title = get_the_title( $post_id );
echo esc_html( wp_trim_words( $title, 12, '…' ) );
?>
Replace $post_id with the relevant post ID and 12 with the word limit that fits your component. In The Loop, you can call get_the_title() without an argument to retrieve the current post’s title. The function applies the the_title filter, so plugins or themes that filter titles can affect the returned string. See WordPress’s get_the_title() reference.
wp_trim_words() accepts the text, a word count, and an optional suffix. It returns a string, strips tags, and uses an ellipsis by default when the text exceeds the limit. The example supplies … explicitly. WordPress notes that for languages where words are counted by individual characters, the count may operate on characters instead; the function also passes through the wp_trim_words filter.
#1 Best Overall
Escape the result for its output context
The example uses esc_html() because the shortened title is printed as text in HTML. If you put it in an HTML attribute instead, escape it with the function intended for attributes. Do not assume that a title template tag makes output safe by itself: WordPress documents that the_title() output is unescaped.
the_title() is a display-oriented template tag and echoes by default. Its third argument can request the title as a string, but retrieving the title with get_the_title() is a straightforward option when you need to pass it into another function before output.
Rank #2
Choose the limit that matches the layout
A word count is useful when approximate length is acceptable, but it does not guarantee a fixed number of characters or a consistent visual width. There is no universally supported number of words for a WordPress title: choose a limit for the particular card, menu, or other component, then check representative titles, translations, and screen sizes.
Use display width when visual fit matters
For a width-based cap, PHP provides mb_strimwidth(). The PHP manual defines its width calculation this way: halfwidth characters count as one unit and fullwidth characters as two. Confirm that the mbstring extension is available in the environment where your code runs. Negative width is deprecated as of PHP 8.3.
The Tool Desk
Outbyte Driver Updater FREEFix the driver behind crashes, sound loss and screen glitchesFind Drivers →Outbyte PC Repair FREEClear out junk files and repair common Windows errorsFree Scan →Do not casually replace a width-aware approach with substr() for multilingual titles. Bytes, characters, grapheme clusters, and display width are different units; use one that matches the design requirement. The cited PHP reference establishes display-width truncation, not a universal character-truncation recipe for every language and encoding.
| Approach | What it limits | Best fit | Considerations |
|---|---|---|---|
wp_trim_words() |
Words, with character-count behavior for some languages | A component where approximate title length is sufficient | WordPress-native; returns a string and accepts an optional suffix. |
mb_strimwidth() |
Display width, counting halfwidth characters as one unit and fullwidth as two | A component that needs a width-based cap | Requires the mbstring extension; PHP 8.3 deprecates negative width. |
Apply the change only where it belongs
Trimming at the template call site keeps the change local: the stored title and other displays remain untouched. A global the_title filter can alter titles in multiple places, so use one only when that broader behavior is intended. If you do use a filter, constrain it to the intended context and post type, return the filtered string, and check how the active theme and plugins interact with it.
Rank #4
Also distinguish the visible post heading from the browser tab title. The wp_title hook filters the HTML document title; it is not the API for shortening an individual visible post title. For document-title behavior, inspect the active theme’s implementation and WordPress’s wp_get_document_title() reference.
Quick Recap
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.




