• I have meta field v_url.

    As I am moving to block theme, the best solution would be if I can move this field value into the iframe of the first block in each post that contains this field (field is not empty).

    For example, I have
    v_url value https://www.youtube.com/embed/xxxx

    Move this to first block of each posts with v_url field not being empty as:

    <iframe width="1223" height="688" src="https://www.youtube.com/embed/xxxx" title="" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" allowfullscreen></iframe>
Viewing 1 replies (of 1 total)
  • Hi,

    Bulk modifying posts is a bit dangerous, thus I’d propose to create a plugin or use the Snippets plugin to insert this piece of code

    add_filter( 'the_content', function( $content ) {
        $v_url = get_post_meta( get_the_ID(), 'v_url', true );
        if ( $v_url ) {
            $iframe = '<iframe src="' . esc_attr( $v_url ) . '"></iframe>';
            $content = $iframe . $content;
        }
        return $content;
    } );

    If the currently displayed post contains the post meta v_url, then use it to put an iframe at the start of the post content.

    When you update a post, make sure to remove the meta value so that it will no longer prepend that iframe.

    Does this help?

Viewing 1 replies (of 1 total)
  • The topic ‘Is it possible to move meta key value into first block?’ is closed to new replies.