• OK, so I am using this tag:

    <?php wp_list_categories(‘title_li=<h2>Categories</h2>’ ); ?>

    to display a list of categories in my sidebar. I do not want the category title to be in an

    • , I just want it to be <h2>. Is there anyway I can do that?
    • If I can’t do that, how do I style the Category title (within the li)? I don’t think li h2 will work in the css.

      My widgets are working fine (I have a dynamic sidebar) but my default elements are giving me trouble. Is there any way I can get the default elements to act as widgets, where the titles are given <h2>s before and after?

      It’s just confusing to me. Why use the first list item as the title of a list? And having a heading in an li is odd and I don’t even know if you can style that.

      Any help appreciated.

Viewing 8 replies - 1 through 8 (of 8 total)
  • You may want to try this:
    wp_list_categories
    wp_list_categories('title_li=<h2>' . __('Categories') . '</h2>' );

    You can also achieve this in your register_sidebars function using before_title and after_title.

    Thread Starter cscott5288

    (@cscott5288)

    I tried that, it still places the <h2>Categories</h2> in an li.

    Thread Starter cscott5288

    (@cscott5288)

    See for yourself : https://www.hospiceinform.net/ (right sidebar)

    I don’t know what theme your using but check your sidebar.php and/or your functions.php file. It looks like it’s starting your sidebar in a list.

    Thread Starter cscott5288

    (@cscott5288)

    I am using my own theme which I am testing before using it on my site.

    Here is the sidebar:

    <div id=”sidebar”>
    <?php if ( !function_exists(‘dynamic_sidebar’)
    || !dynamic_sidebar(“Right Sidebar”) ) : ?>

    <?php wp_list_categories(‘title_li=<h2>’ . __(‘Categories’) . ‘</h2>’ ); ?>

    <?php wp_get_archives( $args ); ?>

    <?php wp_list_comments( $args ); ?>

    <?php endif; ?>

    </div>

    Here is the register for the sidebar in functions.php

    if ( function_exists(‘register_sidebar’) )
    register_sidebar(array(
    ‘name’ => ‘Right Sidebar’,
    ‘before_widget’ => ”,
    ‘after_widget’ => ”,
    ‘before_title’ => ‘<h2>’,
    ‘after_title’ => ‘</h2>’,
    ));

    Thread Starter cscott5288

    (@cscott5288)

    P.S. I realize I have <h2> registered in the sidebar as well as placed into the php. I took it out but that wasn’t the cause of the problem.

    Thread Starter cscott5288

    (@cscott5288)

    Any help would be highly appreciated ?? I just need to know how to style the heading within the first li in the ul or to somehow get rid of the li, so there is only a heading.

    did you solve it? or what is the problem?

    this is the html of the sidebar top from the browser:

    <div id="sidebar">
    
    <h2>Categories</h2>		<ul>
    	<li class="cat-item cat-item-9"><a href="https://www.hospice....

    no ‘li’ with the header.
    simply #sidebar h2 { ..styles.. }

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘Trying to show category title not in an li’ is closed to new replies.