Make WordPress Core

Opened 4 years ago

Closed 3 years ago

#12247 closed defect (bug) (fixed)

wp_link_pages link_before link_after used wrong and not just with <a> tags

Reported by: openmtl Owned by:
Milestone: 3.0 Priority: low
Severity: trivial Version: 2.9.1
Component: Template Keywords: has-patch
Focuses: Cc:


In the function wp_link_pages() in /wp-includes/post-template.php then there is an illogical use of the link_before and link_after options. The function states that....

* 'link_before' - Default is '' (string). The html or text to prepend to each
 *      Pages link inside the <a> tag.
 * 'link_after' - Default is '' (string). The html or text to append to each
 *      Pages link inside the <a> tag.

but this actually wraps around any page number irrespective of it of has the 'a' href tag or not i.e. the current page that you are on which is not an 'a' tag also gets this link_before and link_after styling. That is wrong. The fix is easy. In post-template.php remove the lines 590 to 594 where it says,

$output .= $link_before;
$output .= $j;
$output .= $link_after;
if ( ($i != $page) || ((!$more) && ($page==1)) )
   $output .= '</a>';

then change this to e.g.,

if ( ($i != $page) || ((!$more) && ($page==1)) ) {
	$output .= $link_before;
	$output .= $j;
	$output .= $link_after;
	$output .= '</a>';
} else {
	$output .= $j;

I've tested this on 2.9.1 and the effect is that BEFORE my patch if $link_before and $link_after is used then all the numbers of the (sub)pages at the bottom of a page get the characters before and after, e.g.,

[1] [2] [3] [4] [5]

whereas if my patch is added then, correctly, only those subpages that actually are 'a' tags get the text before and after e.g. it looks like,

[1] 2 [3] [4] [5]

Also that function should really also style non-links too but thats a new feature not a bug.

Change History (6)

comment:1 nacin4 years ago

  • Component changed from Themes to Template
  • Milestone changed from Unassigned to 3.0

Changing the functionality of this could break things. Maybe we should just update the docs. Setting to 3.0.

comment:2 dd324 years ago

I'd agree with updating the documentation here, I'm thinking that people are going to want a standard html applied before/after each item more often than not.

comment:3 nacin4 years ago

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

(In [14687]) Clarify that link_before and link_after text for wp_list_pages also applies to the current page which doesn't actually have a link. fixes #12247.

comment:4 follow-up: scottcropper3 years ago

  • Cc scott.cropper@… added
  • Keywords dev-feedback added; has-patch removed
  • Resolution fixed deleted
  • Severity changed from trivial to minor
  • Status changed from closed to reopened

In testing this I've found it to work however the link before and link after gets applied to the text and not the link. Example :

if before and after are set to a list <ul> and </ul> respectively

and link_before and link_after are set to list items <li> and </li> respectively you end up with :

<a href="link"><li>2</li></a>
<a href="link"><li>3</li></a>

Rather than what I think would be expected :

<li><a href="link">2</a></li>
<li><a href="link">3</a></li>

comment:5 in reply to: ↑ 4 aaroncampbell3 years ago

Since this was fixed in 3.0 and closed, I'd recommend opening a new ticket and referencing this one instead of reopening this one.

comment:6 ocean903 years ago

  • Keywords has-patch added; dev-feedback removed
  • Resolution set to fixed
  • Severity changed from minor to trivial
  • Status changed from reopened to closed

Please open a new ticket if you think it's a bug.

But from the inline docs I can say, that this is intentionally.

nacin: Changing the functionality of this could break things.

Note: See TracTickets for help on using tickets.