Is it possible to somehow make it so that the iframe tag does not turn into the p tag in the body of the article? I want to limit the width of the text to 800 pixels, but at the same time that the pictures and videos are 100%. If I restrict the tag p {width: 800px; margin: 0 auto;} p {width: 800px; margin: 0 auto;} turns out that the text is centered and the images remain stretched by 100%, but the video is also compressed by 800 pixels, as it is wrapped in the p tag automatically.

enter image description here

    1 answer 1

    Add the following code to the functions.php file of your theme:

     function strip_ptags_on_iframe($content) { return preg_replace('/<p>\s*(<iframe.*>*.<\/iframe>)\s*<\/p>/iU', '\1', $content); } add_filter('the_content', 'strip_ptags_on_iframe'); 

    This code will automatically cut the p tags around the iframe . Similarly, you can trim p around other tags, such as object , img , script , etc.

    • Thanks, I see! - Anton Essential
    • Probably you know, there is still such a problem, when I am logged in as an author. For some reason I cannot publish an iframe, when the admin is ok, I put the iframe in the body of the article, publish, click on the link and see the video in the body of the article, but when I do the post by the author and add an iframe and after the publication in the body of the article there is everything except the iframe, for some reason he cuts it out, maybe this is a problem in the subject? - Anton Essential
    • one
      @AntonEssential, In short, you need to add a tag to the allowed ones and you can do it like this: add_action( 'init', function () {global $allowedtags; $allowedtags['iframe'] = array('src' => array(), 'height' => array(), 'width' => array());} ); . - Pyramidhead