How to show meta value code HTML after x paragraph

Question

I have a custom field for some posts, that has the HTML code.

I want to show this code after x paragraph in the wordpress loop.

I tried with the following code, but it doens’t works.

function prefix_insert_after_para( $ads, $content ) {
    if ( ! is_array( $ads ) ) {
        return $content;
    }

    $closing_p = '</p>';
    $paragraphs = explode( $closing_p, $content );

    foreach ($paragraphs as $index => $paragraph) {
        if ( trim( $paragraph ) ) {
            $paragraphs[$index] .= $closing_p;
        }

        $n = $index + 1;
        if ( isset( $ads[ $n ] ) ) {
            $paragraphs[$index] .= $ads[ $n ];
        }
    }

    return implode( '', $paragraphs );
}

add_filter( 'the_content', 'prefix_insert_post' );
function prefix_insert_post( $content ) {
    if ( is_single() && ! is_admin() ) {
        $content = prefix_insert_after_para( array(
           //  The format is: '{PARAGRAPH_NUMBER}' => 'AD_CODE',
           
            '4' => '' . echo get_post_meta(get_the_ID(), 'namevalue', TRUE) . '' ,      
            
        ), $content );
    }

    return $content;
}

With this code seems that the problem is ‘echo’. Someone can help me?

0
, , Giulio 3 months 0 Answers 45 views 0

Leave an answer