Opened 6 years ago
Last modified 4 years ago
#4004 new enhancement
New filter for page title attribute in wp_list_pages output
| Reported by: |
|
Owned by: |
|
|---|---|---|---|
| Priority: | normal | Milestone: | Future Release |
| Component: | Template | Version: | 2.1.3 |
| Severity: | normal | Keywords: | needs-patch filter wp_list_pages |
| Cc: | westi |
Description
While developing a new theme I realised that the default title attribute for wp_list_pages was to just to reuse the title of the page with no option to change it. Not exactly useful...
I therefore propose a new filter on the title attribute to allow a theme/plugin developer the option of changing the text to whatever they like.
The new filter takes the title attribute and the $page variable as well, so that any post/page related information can also be used... for example the post meta.
Attachments (3)
Change History (20)
- Keywords commit added
- Milestone changed from 2.1.3 to 2.2
- Owner changed from anonymous to ryan
- Summary changed from New filter for page title attribute to New filter for page title attribute in wp_list_pages output
+1
My only question is regarding the naming of the filter as it is being called from within the Page_Walker class - maybe it should reference that instead.
I am interested to know why have you decided to remove the $page attribute added to the filter. Surely this is useful for plugin developers to get more info about this post, as just passing in the title gives no extra information.
I agree with Dickie here. We need to pass $page through to the filter otherwise it is pretty useless as it has no other context.
If a plugin author wanted to use this filter they need some context to work with.
In the trunk we now run it through the_title, both on the attribute and the page title.
Replying to rob1n:
In the trunk we now run it through the_title, both on the attribute and the page title.
I don't think that helps much.
How can we tell the context of the call? i.e. attribute/content.
I agree adding the the_title filter to the title when used as content makes sense.
I feel we still need a new filter for when it is the title attribute - and we still need to pass the post object through for anyone that wants it here as they can't easily get the context in any other way as posts titles are not unique.
Just to give some context to this.
For example... I set the page title to be "About" but when the visitor to my website hovers over the link in the menu bar for the About page I do not want it to say "About" but perhaps
"Visit my about page" or "Go to the page with information about me", this could either be hard coded in the plug-in (not good perhaps) or gleaned from the page meta data, or a mixture of both.
The point is, I need different text for both the Page name itself AND the page title attribute.
The way it was working in the supplied patch file was fine, the only issue I could see was the name of the filter itself (and to be honest I was not sure about that as it was not directly in wp_list_pages, but I went with it anyway as it seemed the most logical)
Replying to rob1n:
In the trunk we now run it through the_title, both on the attribute and the page title.
In this patch I have also taken to opportunity to only run "the_title" filter once (as it was being run twice), then run the result of that filter through the attribute title filter "walker_page_title".
comment:10
Dickie — 6 years ago
I am not sure about my last patch now, if we really must pass the title Attribute through "the_title" filter, then the attribute filter should go second. (like this)
// As the post title is needed in two places, rather than process the filter twice, store it in $title
$title = apply_filters('the_title', $page->post_title);
// The title will also be run through another filter to determine the title attribute for the link
$output .= $indent . '<li class="' . $css_class . '"><a href="' . get_page_link($page->ID) . '" title="' . attribute_escape(apply_filters('walker_page_title',$title, $page)) . '">' . $title . '</a>';
But I cant help feeling that this is a bad idea... the anchor title attribute is a label for the link, and as such is likely to be completely different from the Title of the post itself. therefore I think that this solution is the better one, which is more similar to my first patch before the "the_title" filters were added
$output .= $indent . '<li class="' . $css_class . '"><a href="' . get_page_link($page->ID) . '" title="' . attribute_escape(apply_filters('walker_page_title',$page->post_title, $page)) . '">' . apply_filters('the_title', $page->post_title) . '</a>';
Also, I still feel strongly and agree with westi on this, that the $page var needs to be sent to the filter to give it some context.
comment:11
foolswisdom — 6 years ago
- Milestone changed from 2.2 to 2.3
comment:12
rob1n — 6 years ago
- Keywords commit removed
comment:13
ryan — 6 years ago
- Milestone changed from 2.3 to 2.4
comment:14
westi — 6 years ago
Relates to #4893
comment:16
ffemtcj — 5 years ago
- Milestone changed from 2.5 to 2.6
- Keywords needs-patch added; has-patch removed
- Milestone changed from 2.9 to Future Release

Patch File for Filter Change