• Hi, i’m using bootstrap to get a responsive, design, so i wanna tweak the html for image insertion using the media gallery:

    So my php is this:

    function html_img($html, $id, $alt, $title, $align, $url, $size )
    {
        $url = wp_get_attachment_url($id); // Grab the current image URL
        $alternatif = $alt != "" ? $alt : $url;
        $class = 'img-responsive';
        if (  $align === 'left')
        //$size === 'article_300_left')
    	{
    		$html = '<div class=\'row vertical-align\'><div class= \'col-md-4 col-sm-12\'>';
    		$html .= "<img src=\"$url\" class=\"$class\" alt=\"$alternatif\"></div><div class=\"col-md-8 col-sm-12 vertical-align\">VOTRE TEXTE ENTRE CES DEUX BALISES</div>/<div>" ;
        }
       return $html;
    }

    When editing from text, i see this added to the page:

    <div class='row vertical-align'><div class= 'col-md-4 col-sm-12'><img src="https://127.0.0.1/wordpress/wp-content/uploads/2015/07/inchallE3.gif" class="img-responsive" alt="https://127.0.0.1/wordpress/wp-content/uploads/2015/07/inchallE3.gif"></div><div class="col-md-8 col-sm-12 vertical-align">VOTRE TEXTE ENTRE CES DEUX BALISES</div>/<div>

    but if i go back to visual and than to text, the actual code is this:

    <div class="row vertical-align">
    <div class="col-md-4 col-sm-12"><img class="img-responsive" src="https://127.0.0.1/wordpress/wp-content/uploads/2015/07/inchallE3.gif" alt="https://127.0.0.1/wordpress/wp-content/uploads/2015/07/inchallE3.gif" /></div>
    <div class="col-md-8 col-sm-12 vertical-align">VOTRE TEXTE ENTRE CES DEUX BALISES</div>
    /
    <div></div>
    </div>

    Why the hell is wordpress adding this / and this opening div tag?
    It messes with my page layout, and it’s not w3c validated anymore.

    Can someone help?

Viewing 2 replies - 1 through 2 (of 2 total)
  • WordPress is attempting to keep your HTML well-formatted, etc. using:
    https://codex.www.ads-software.com/Function_Reference/wpautop

    There are some plugins you could try to get the behavior you want. The first decent one I found in a hurry was:
    https://www.ads-software.com/plugins/ps-disable-auto-formatting/

    Beware that sometimes such plugins can end up disabling more than you really want disabled. That said, there’s no harm in trying. If this one doesn’t work out try a search for disabling wordpress auto formatting.

    Good luck!

    Thread Starter devolution

    (@devolution)

    Thanks, i tried removing the wpautop filter from functions.php, the page gets all ugly (well, as it should), but wordpress is still adding the / and the <div> :/

    I’m mean it’s weird, the $html returned by the function is EXACTLY the one i want, but it seems it’s the editor that adds div EVEN IF i’m already in html mode.

    Edit: ok, after re-re-re-re-checking it, it was a typo in my php.

    thanks for the help ??

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Image Editor weird div appears for no reason’ is closed to new replies.