Support » Developing with WordPress » i want change h2 tag of dynamic sidebar.but before_title not work.

  • bgeg

    (@bgeg)


    i want change h2 element of dynamic sidebar.
    i think it not good for search engine.

    before_widget and after_widget key work well with the code written below.
    but before_title and after_title key not work.
    please tell me the some advice.

    # sidebar.php
    <?php dynamic_sidebar( 'sidebar1' ); ?>

    # function.php

    if (function_exists('register_sidebar')) {
    		register_sidebar(array(
    	   'name' => 'sidebar_one',
    	   'id' => 'sidebar1',
    	   'description' => 'this is sidebar1',
    	   'before_widget'=>'<nav class="sidebar__wrapper">',
    	   'after_widget'=>'</nav>',
    	   'before_title'=>'<h2 class="sidebar__title">',
    	   'after_title'=>'</h2>',));
    	   }

    # image of result
    https://i.imgur.com/FRk6dbh.jpg

Viewing 6 replies - 1 through 6 (of 6 total)
  • Vijay Hardaha

    (@vijayhardaha)

    It’s different in block editor widgets, You can click on title then change the title tag in block editor

    Thread Starter bgeg

    (@bgeg)

    >>Vijay Hardaha (@vijayhardaha)
    thanks for comment.
    i can change h2 tag of sidebar in block editor.
    before_title and after_title function disabled in now wordpress?

    Moderator bcworkz

    (@bcworkz)

    I have a child theme of twenty twenty-one. Your code works as expected there. I only changed the sidebar ID so it does not conflict with sidebars already registered.

    Thread Starter bgeg

    (@bgeg)

    >>bcworkz (@bcworkz)
    thanks for comment.
    i used original theme.
    it may have some problem.

    thanks.

    before_title and after_title still work with classic widgets.

    Thread Starter bgeg

    (@bgeg)

    >>Vijay Hardaha (@vijayhardaha)
    thanks for comment.
    probably i missed code something.
    i will try to improve something.

Viewing 6 replies - 1 through 6 (of 6 total)
  • You must be logged in to reply to this topic.