Make WordPress Core

Opened 11 years ago

Closed 10 years ago

Last modified 10 years ago

#26987 closed defect (bug) (worksforme)

Bug in wp_list_pages(), caused by start_lvl()

Reported by: awelzel's profile awelzel Owned by:
Milestone: Priority: normal
Severity: normal Version: 3.8.1
Component: Posts, Post Types Keywords:
Focuses: Cc:

Description

start_lvl() in wp-includes/post-template.php adds a new line for the next level in the page list.

	function start_lvl( &$output, $depth = 0, $args = array() ) {
		$indent = str_repeat("\t", $depth);
		$output .= "\n$indent<ul class='children'>\n";
	}

This causes an </p> to be inserted in the page list generated by wp_list_pages() because something in the core assumes the new line to be the end of a paragraph.

Example: See <http://arnowelzel.de/wp/sitemap>

Possible bug fix: Just remove the newline.

	function start_lvl( &$output, $depth = 0, $args = array() ) {
		$indent = str_repeat("\t", $depth);
		$output .= "$indent<ul class='children'>\n";
	}

As suggested in the nearly two year old(!) forum post:

http://wordpress.org/support/topic/wp_list_pages-creates-extra-paragraph-only-on-first-child

Change History (13)

#1 in reply to: ↑ description @awelzel
11 years ago

Since I need a working sitemap without empty lines I applied the suggested fix to my WordPress installation - so the example will show the result with the fix applied.

#2 @aubreypwd
11 years ago

  • Keywords 2nd-opinion added

I looked into this and could not duplicate the stray </p>. See https://cloudup.com/cJbLFhhCATf https://cloudup.com/cWbFB94w1MH https://cloudup.com/cp6ph3YAkF8

I tried it as a shortcode, I also added it to the post via theme modification, still couldn't get it to show up. Maybe it's fixed in 3.8+?

#3 @aubreypwd
11 years ago

  • Keywords reporter-feedback added

#4 @awelzel
11 years ago

This only occurs for the first sub page in the whole tree.

For example - if you have this structure:

  Page 1
    Page 1.1
    Page 1.2
  Page 2
  Page 3
  ...

Then you will get a stray </p> after Page 1.

And no - this is not fixed yet in WP 3.8.1.

See example: http://arnowelzel.de/wpdemo/sitemap-en

...
<h2 class="wsp-pages-title">Pages</h2>
<ul class="wsp-pages-list">
<li class="page_item page-item-275 page_item_has_children"><a href="http://arnowelzel.de/wpdemo/tools-en">Tools</a></p>
<ul class='children'>
<li class="page_item page-item-407"><a href="http://arnowelzel.de/wpdemo/tools-en/gema-vs-youtube">Gema vs YouTube</a></li>
...
Last edited 11 years ago by awelzel (previous) (diff)

#5 @aubreypwd
11 years ago

Okay, let me give it a try again. Took a screenshot of what's happening on your site https://cloudup.com/cIT03rwdsMT for anyone else who runs across this ticket.

#6 @awelzel
11 years ago

Well - you can see - there is a <p> element where it shouldn't be.

But: What you published on https://cloudup.com/cIT03rwdsMT is not what gets delivered by WordPress. It seems your browser automatically cleans up malformed code.

See: http://validator.w3.org/check?uri=http%3A%2F%2Farnowelzel.de%2Fwpdemo%2Fsitemap-en

And this is the version which will soon become my live site with the proposed bug fix (leave out the extra \n in start_lvl()): http://arnowelzel.de/wp/en/sitemap

Last edited 11 years ago by awelzel (previous) (diff)

#7 @aubreypwd
11 years ago

I wrote a small plugin https://gist.github.com/aubreypwd/0515320631dfba888c04 to test this. I also imported the theme unit data so I'd have lots of sub-pages to work with, and I can't seem to duplicate the problem, see https://cloudup.com/cbv2srEDHIi and https://cloudup.com/cJyTrgVD8D5

I even curl'd the source https://cloudup.com/c7M4IZW9KU0 and am not seeing a stray <p> anymore https://cloudup.com/cymMhCn4gos

What plugin are you using to create your sitemap?

This ticket was mentioned in IRC in #wordpress-dev by aubreypwd. View the logs.


11 years ago

#9 @aubreypwd
11 years ago

  • Keywords reporter-feedback removed

I still don't think that this is a core issue, because the only way I can duplicate the issue is by applying the_content(), see https://gist.github.com/aubreypwd/d38291898529be1ec351#file-test_v2-php-L47 and https://cloudup.com/cKD0OqzHzUG

But, when I don't apply the_content() to the return, I don't get the stray <p>. I possibly suspect https://plugins.trac.wordpress.org/browser/wp-sitemap-page/trunk/wp-sitemap-page.php#L502 in the plugin (I'm assuming this is the plugin you're using) that applies that function multiple times to the $return string.

#10 @awelzel
11 years ago

Yes, I use the wp-sitemap-page plugin. But I can not see any call of the_content() in wsp_wp_sitemap_page_func() or any of the functions called by that.

In fact your testcase will produce a stray </p> here as well, even without the_content() - see: http://arnowelzel.de/wpdemo/sitemap-test

To be sure that this is not caused by some code in the theme, I also changed the theme to the "official" Twenty-Fourteen theme by WordPress.

#11 follow-up: @DrewAPicture
10 years ago

  • Component changed from General to Posts, Post Types
  • Keywords 2nd-opinion removed
  • Milestone Awaiting Review deleted
  • Resolution set to worksforme
  • Status changed from new to closed

I'm unable to reproduce your issue with a clean install of the latest version of WordPress and no plugins installed. Please feel free to reopen the ticket if you continue to have problems.

#12 in reply to: ↑ 11 @awelzel
10 years ago

Replying to DrewAPicture:

I'm unable to reproduce your issue with a clean install of the latest version of WordPress and no plugins installed. Please feel free to reopen the ticket if you continue to have problems.

It's solved. I don't have this problem any longer. I found out the real cause of my problems when integrating "Cleaner Gallery" which also had problems with stray </p>. See https://wordpress.org/support/topic/invalid-html-4. In the end there was a wpautop() issue with the template I used.

#13 @DrewAPicture
10 years ago

Thanks for following up :-)

Note: See TracTickets for help on using tickets.