Publishing just a Facebook URL without full code snippet

Note that Facebook is a registered oEmbed provider in the WordPress core.

You could e.g. use the pre_oembed_result filter, before the HTTP request is made, to cancel it and override it to your needs.

Here’s an example for Facebook posts:

add_filter( 'pre_oembed_result', function ( $result, $url, $args )
{ 
    // override the HTML result for Facebook posts, that will be saved into postmeta table
    if( preg_match( '#https?://www\.facebook\.com/.*/posts/.*#i', $url ) )
        $result = sprintf( 
            '<div class="fb-post" data-href="https://wordpress.stackexchange.com/questions/253385/%s">%s</div>',
            esc_url( $url ), 
            esc_url( $url ) 
        );

    return $result;

}, 10, 3 );

When you paste a Facebook post url, into the post content editor, it will also show the modified oEmbed result, with our snippet.

The oEmbed results are cached by default in the postmeta table, for DAY_IN_SECONDS (24 hours).

We can play with the oembed_ttl filter, like here, but in the meanwhile we can also filter the cached output with the embed_oembed_html filter.

Here’s an example:

add_filter( 'embed_oembed_html', function( $cache, $url, $attr, $post_id )
{
    // override the cached HTML result for Facebook posts
    if( preg_match( '#https?://www\.facebook\.com/.*/posts/.*#i', $url ) )
        $cache = sprintf( 
            '<div class="fb-post" data-href="https://wordpress.stackexchange.com/questions/253385/%s">%s</div>',
            esc_url( $url ), 
            esc_url( $url ) 
        );

    return $cache;

}, 10, 4 );