{"id":230,"date":"2012-04-20T13:41:49","date_gmt":"2012-04-20T18:41:49","guid":{"rendered":"http:\/\/www.marcblase.com\/blog\/?p=230"},"modified":"2013-04-18T11:17:54","modified_gmt":"2013-04-18T16:17:54","slug":"stop-wordpress-from-wrapping-up-with","status":"publish","type":"post","link":"https:\/\/ma.rcbla.se\/blog\/2012\/04\/stop-wordpress-from-wrapping-up-with\/","title":{"rendered":"Stop WordPress from wrapping &lt;img&gt; up with &lt;p&gt;"},"content":{"rendered":"<p>Img: &#8220;WordPress, why you wanna wrap me up?&#8221;<\/p>\n<p>WordPress: &#8220;You looked cold.&#8221;<\/p>\n<p>Img: &#8220;Well I&#8217;m not.&#8221;<\/p>\n<p>WordPress: &#8220;Oh.&#8221;<\/p>\n<p>Here&#8217;s how to stop that from happening:<\/p>\n<pre class=\"brush: php; title: ; notranslate\" title=\"\">\r\n\/\/ stop wordpress from wrapping images in &lt;p&gt; tags\r\nfunction filter_ptags_on_images($content) {\r\n    \/\/ do a regular expression replace...\r\n    \/\/ find all p tags that have just\r\n    \/\/ &lt;p&gt;maybe some white space&lt;img all stuff up to \/&gt; then maybe whitespace &lt;\/p&gt;\r\n    \/\/ replace it with just the image tag...\r\n    return preg_replace('\/&lt;p&gt;\\s*(&lt;a .*&gt;)?\\s*(&lt;img .* \\\/&gt;)\\s*(&lt;\\\/a&gt;)?\\s*&lt;\\\/p&gt;\/iU', '\\1\\2\\3', $content);\r\n}\r\n\/\/ we want it to be run after the autop stuff... 10 is default.\r\nadd_filter('the_content', 'filter_ptags_on_images');\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Img: &#8220;WordPress, why you wanna wrap me up?&#8221; WordPress: &#8220;You looked cold.&#8221; Img: &#8220;Well I&#8217;m not.&#8221; WordPress: &#8220;Oh.&#8221; Here&#8217;s how to stop that from happening: \/\/ stop wordpress from wrapping images in &lt;p&gt; tags function filter_ptags_on_images($content) { \/\/ do a regular expression replace&#8230; \/\/ find all p tags that have just \/\/ &lt;p&gt;maybe some white [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[11,3,13],"tags":[],"class_list":["post-230","post","type-post","status-publish","format-standard","hentry","category-coding","category-discoveries","category-humor"],"_links":{"self":[{"href":"https:\/\/ma.rcbla.se\/blog\/wp-json\/wp\/v2\/posts\/230","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ma.rcbla.se\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ma.rcbla.se\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ma.rcbla.se\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/ma.rcbla.se\/blog\/wp-json\/wp\/v2\/comments?post=230"}],"version-history":[{"count":4,"href":"https:\/\/ma.rcbla.se\/blog\/wp-json\/wp\/v2\/posts\/230\/revisions"}],"predecessor-version":[{"id":340,"href":"https:\/\/ma.rcbla.se\/blog\/wp-json\/wp\/v2\/posts\/230\/revisions\/340"}],"wp:attachment":[{"href":"https:\/\/ma.rcbla.se\/blog\/wp-json\/wp\/v2\/media?parent=230"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ma.rcbla.se\/blog\/wp-json\/wp\/v2\/categories?post=230"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ma.rcbla.se\/blog\/wp-json\/wp\/v2\/tags?post=230"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}