Skip to content
WordPressRule: list•Reviewed Oct 2026

Ensure ul and ol list containers only contain li elements in WordPress

`<ul>` and `<ol>` tags must contain only `<li>` elements, `<script>`, or `<template>` tags.

What's wrong

Placing `<div>` directly inside `<ul>` breaks list semantics and item numbering.

Who it affects

Screen readers announce incorrect item counts or stop announcing list structure.

How to fix on WordPress

Ensure custom menu walkers and post loop templates do not inject `<div>` as direct children of `<ul>`.

Code example

Problematic Code
PHP
<ul class="custom-nav">
  <span class="nav-group">
    <li><a href="#">Home</a></li>
  </span>
</ul>
Recommended Accessible Code
PHP
<ul class="custom-nav">
  <li class="nav-item"><a href="#">Home</a></li>
</ul>

How to check your fix

Validate HTML using W3C validator or DevTools to verify all direct children of `<ul>` and `<ol>` are `<li>` tags.

Check if your site has this issue

Scan any public store page free against WCAG 2.2 AA in 30 seconds.

Your session has ended

Sign in again to carry on. Anything you typed on this page is kept.

Signed in another way? Use another method (opens a new tab)