remove the wrapping of text widget or

When I write a quote in the text widget and displayed the text is wrapped as…

<div class="textwidget">My text...</div>.
I would like to remove the div and put simply “My text…”.

Read More

For Example:

Current output

<div class="container">
   <div class="textwidget">
       My text...
   </div>
</div>

Required output:

 <div class="container">
     My text...
 </div>

Related posts

Leave a Reply

3 comments

  1. jQuery way :

    $('.textwidget').contents().unwrap();
    

    PHP way :

    $s = '<div class="textwidget"><div class=“textwidget”>My text...</div></div>';
    echo preg_replace( '/<div class="container">(.*?)</div>/' , '$1' , $s);
    

    Ref : https://stackoverflow.com/a/12495139/622813


    So WordPress way : (Hacks way)

    Functions.php (get dynamic_sidebar as return)

    function get_dynamic_sidebar($i = 1) {
       $c = '';
       ob_start();
       dynamic_sidebar($i);
       $c = ob_get_clean();
       return $c;
    }
    

    Your template : (So replace it)

    echo preg_replace( '/<div class="textwidget">(.*?)</div>/' , '$1' , get_dynamic_sidebar('sidebar_smlinks') );
    
  2. Could you please check below code?

    <script>
    jQuery( document ).ready(function() {
        jQuery( ".container .textwidget" ).removeClass( "textwidget" );
    });
    </script>