pocketsize / bolts-wp

A starter theme for WordPress using Bolts
2 stars 0 forks source link

Filter for embed wrappers only works for auto-generated embed elements #62

Closed djurnamn closed 4 years ago

djurnamn commented 4 years ago

This makes user entered embed elements in content not work responsively.

We should add something like this to functions/filters.php:

/**
 * Wrap auto-generated embed elements in a div with a custom class
 */

function bolts_wp_wrap_auto_embed_elements($html)
{
    return '<div class="embed-wrapper">' . $html . '</div>';
}
add_filter('embed_oembed_html', 'bolts_wp_wrap_auto_embed_elements', 10, 3);
add_filter('video_embed_html', 'bolts_wp_wrap_auto_embed_elements');

/**
 * Wrap user entered embed elements in a div with a custom class
 */

function bolts_wp_wrap_user_embed_elements($content)
{
    $pattern = '~<iframe.*</iframe>|<embed.*</embed>~';
    preg_match_all($pattern, $content, $matches);

    foreach ($matches[0] as $element) {
        $wrapped_element = '<div class="embed-wrapper">' . $element . '</div>';
        $content = str_replace($element, $wrapped_element, $content);
    }

    return $content;    
}
add_filter('the_content', 'bolts_wp_wrap_user_embed_elements');
andreekeberg commented 4 years ago

Fixed in #77