• I’m new to wordpress, and I notice that for inexplicable reasons if I insert an image into a page, it is automatically wrapped in a paragraph tag. The <p> tag doesn’t actually show up in the HTML editor, so I can’t remove it manually, and that would somewhat defeat the purpose of using this as a CMS anyhow. So is there a way to stop that behavior, editing some file somewhere? I read somewhere that wrapping the image in a div would solve this, but that also defeats the purpose

    Any help would be greatly apreciated

Viewing 3 replies - 1 through 3 (of 3 total)
  • May be a theme function? Or are you entering text around the image that you are trying to align it to that could be causing it? WordPress does not do this for me.

    HTML img elements must be contained within a block element. I think things are a bit different for HTML5, but all the HTML5 examples I’ve seen still seem to respect this.

    HTML4
    HTML5

    So it’s not inexplicable, it’s just producing valid HTML.

    HTH

    PAE

    Hi there, I do believe that this code in post-template.php may be at the root of what you are experiencing. Please take care not to edit the core files directly, but to use your themes functions.php file to hook in. (Check Codex if this is all Greek to you).

    /**
     * Wrap attachment in <<p>> element before content.
     *
     * @since 2.0.0
     * @uses apply_filters() Calls 'prepend_attachment' hook on HTML content.
     *
     * @param string $content
     * @return string
     */
    function prepend_attachment($content) {
    	global $post;
    
    	if ( empty($post->post_type) || $post->post_type != 'attachment' )
    		return $content;
    
    	$p = '<p class="attachment">';
    	// show the medium sized image representation of the attachment if available, and link to the raw file
    	$p .= wp_get_attachment_link(0, 'medium', false);
    	$p .= '</p>';
    	$p = apply_filters('prepend_attachment', $p);
    
    	return "$p\n$content";
    }
Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘IMGs wrapped in P tags’ is closed to new replies.