• Small example to reproduce the bug:

    Open your sidebar.php and add this:
    <?php wp_list_categories('title_li=<h2>Pages&Categories</h2>'); ?>
    or
    <?php wp_list_categories('title_li=<h2>Pages & Categories</h2>'); ?>
    or
    <?php wp_list_categories('title_li=<h2>Pages &amp; Categories</h2>'); ?>

    As result “Categories</h2>” part will disappear.

    origin of bug : “Categories</h2>” is considered by wp_parse_args as an unkown argument (because of the “&”).

Viewing 3 replies - 1 through 3 (of 3 total)
  • Shouldn’t the value for the “title_li” attribute be URI-encoded? I haven’t tested this, but I’d suspect that the appropriate way to do what you’re trying to would be to URI-encode your HTML as follows:

    <?php wp_list_categories('title_li=%3Ch2%3EPages+%26amp%3B+Categories%3C%2Fh2%3E'); ?>

    Of course, your code might be easier to read if you only bother URI-encoding the “&” symbol as follows:

    <?php wp_list_categories('title_li=<h2>Pages %26amp; Categories</h2>'); ?>

    And you’d have to make sure that any “=” that you wanted output as part of the title li is also URI-encoded.

    If this doesn’t work, then I’d imagine that there is some sort of problem with the wp_parse_args() function.

    In fact, looking into the source code, wp_parse_args uses the WordPress function wp_parse_str() which in turn uses the native PHP function parse_str().

    According to PHP’s documentation, this function parses the supplied string as if it were a query string passed via a URL (i.e. URI-encoded).

    Bear in mind that the wp_parse_str() function also calls the filter hook ‘wp_parse_str’ on the returned array. This means that if any of your plugins make use of this filter then the array will be modified by those plugins. This only applies if you use wp_list_categories() with a string argument rather than array argument.

    Therefore, an alternative solution to URI-encoding would be to supply the argument as an array as follows:

    <?php
    $args = array(
    'title_li' => '<h2>Pages &​amp; Categories</h2>'
    );
    wp_list_categories($args);
    ?>

    very thanks for article!

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘wp_parse_args bug (all WP versions)’ is closed to new replies.