Make WordPress Core

Opened 11 years ago

Closed 11 years ago

Last modified 9 years ago

#23254 closed defect (bug) (fixed)

Empty Page Title Not Handled in Menu System

Reported by: cais's profile cais Owned by: markjaquith's profile markjaquith
Milestone: 3.6 Priority: normal
Severity: normal Version: 3.0
Component: Menus Keywords: has-patch commit
Focuses: Cc:


I noticed some peculiar menu layouts and sorted it out to having some pages with no titles (not sure the actual use case for a page without a title but it is in my test environments).

The Walker class is recognizing the page exists and creating an appropriate <a href=...> wrapper for it but with no Page Title it is not being displayed. If this is by design I think it should be revisited and if this is a defect then the included patch (not very pretty) may offer a possible solution or at least a consideration.

The patch checks if the Page Title is empty and if it is uses the Page ID as the title.

Attachments (4)

post-template.php.patch (46.5 KB) - added by cais 11 years ago.
23254.patch (1.2 KB) - added by SergeyBiryukov 11 years ago.
23254.2.patch (1.2 KB) - added by SergeyBiryukov 11 years ago.
23254.3.patch (1.2 KB) - added by SergeyBiryukov 11 years ago.
With strict comparison

Download all attachments as: .zip

Change History (17)

#1 @cais
11 years ago

This is affecting $wp_version = '3.6-alpha-23288' as well.

#2 follow-up: @DrewAPicture
11 years ago

  • Cc DrewAPicture added
  • Milestone changed from Awaiting Review to 3.6

You can probably boil down the value passed to the filter into a single variable. Something like:

$page_title = empty( $page->post_title ) ? __( 'Page-' ) . $page->ID : $page->post_title;

In trying to reproduce from the standpoint of the menu editor, there are additional issues when working with pages sans-title, namely:

  • Title-less pages added to a menu hold a temporary title of '(Pending)' and the item is dropped completely on save
  • We should really have some kind of title in the metabox list instead of a naked checkbox

#3 @alex-ye
11 years ago

  • Cc nashwan.doaqan@… added

#4 @sunnyratilal
11 years ago

  • Cc sunnyratilal5@… added

#5 @SergeyBiryukov
11 years ago

Instead of 'Page-{ID}', we could probably use the existing '(no title)' string we already use in wp_ajax_find_posts() and _draft_or_post_title():

#7 @SergeyBiryukov
11 years ago

23254.patch handles an empty title in the metabox too, which solves the issues outlined in comment:2.

#8 @SergeyBiryukov
11 years ago

  • Keywords commit added; needs-testing removed
  • Version changed from 3.5 to 3.0

#9 @cais
11 years ago

The reason why I suggested using the Page ID was as a reference to the page in question ... could/should we consider a filter for (each instance?) that text string as part of this ticket?

#10 @SergeyBiryukov
11 years ago

Each instance can be filtered using existing filters: wp_setup_nav_menu_item in wp_setup_nav_menu_item() and the_title in Walker_Page:

23254.2.patch adds the page/item ID.

#11 @cais
11 years ago

I like the new patch with the page/item ID; and, thanks for pointing out those filters.

Although I do find the first one to be rather complicated at first glance while the second seems to make sense and appears to be more direct in its affect. I was thinking something more along the lines of using the same filter hook for all instances but if two are required to address the same output text then that is what we will have to work with.

11 years ago

With strict comparison

#12 @markjaquith
11 years ago

  • Owner set to markjaquith
  • Resolution set to fixed
  • Status changed from new to closed

In 24560:

Keep the Nav Menu walker from blowing up the layout on empty-titled items.

fixes #23254. props cais, SergeyBiryukov.

#13 in reply to: ↑ 2 @SergeyBiryukov
9 years ago

Replying to DrewAPicture:

Title-less pages added to a menu hold a temporary title of '(Pending)' and the item is dropped completely on save

Follow-up: #24146

Note: See TracTickets for help on using tickets.