[wp-trac] [WordPress Trac] #26976: WP should try to set a default title
WordPress Trac
noreply at wordpress.org
Fri Jan 31 17:57:25 UTC 2014
#26976: WP should try to set a default title
-------------------------------------------------+-------------------------
Reporter: Denis-de-Bernardy | Owner:
Type: defect (bug) | Status: new
Priority: normal | Milestone: Awaiting
Component: General | Review
Severity: normal | Version: trunk
Focuses: ui, accessibility, administration, | Keywords:
template |
-------------------------------------------------+-------------------------
When creating a post without a title, various bits and pieces of WP aren't
as user-friendly as they should be.
Among them:
- Occurrences of "(no-title)" in the admin area (e.g. posts list)
- Posts titled after their ID in the Recent Posts widget
Could we add some code in there to try to fill the gaps where relevant,
i.e. in cases where an author who purposely sets no title (for an aside
when not using a custom post type or similar, for instance) would find it
desirable and useful? Namely:
- In the admin area, for post lists
- In the RSS feed, for feed readers
- In widgets, and more generally outside of the loop
Tentative solution that can be dropped as a plugin in the meanwhile, to
see what I mean:
{{{
add_filter('the_title', function($title, $post_id) {
if ($title || in_the_loop() && !is_feed() && !is_admin()) return
$title;
$post = get_post($post_id);
if (trim($post->post_excerpt)) {
$text = $post->post_excerpt;
$text = apply_filters('the_excerpt', $text);
} else {
$text = $post->post_content;
$text = strip_shortcodes($text);
$text = apply_filters('the_content', $text);
$text = str_replace(']]>', ']]>', $text);
}
return wp_trim_words($text, 6);
}, -50, 2);
}}}
--
Ticket URL: <https://core.trac.wordpress.org/ticket/26976>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list