• Resolved jabedbd

    (@jabedbd)


    is there any way to embed youtube video by getting link ftom custom field?

    i use the code bellow, but it’s not works ??

    add_action (‘__after_content_title’, ‘display_custom_fields_block2′);
    function display_custom_fields_block2() {
    if ( ! is_singular()) return;
    $custom_fields2_array = array(
    ‘youtube’ => ‘Watch Film’,
    );
    $output2 = custom_fields2_iteration($custom_fields2_array);
    if (strlen($output2) > 0 )
    echo ‘
    ‘.
    $output2.’
    ‘;
    }
    function custom_fields2_iteration ($custom_fields2_array) {
    $output2 = ”;
    foreach ($custom_fields2_array as $custom_field2 => $label) :
    $custom_field2_value = get_post_meta(get_the_ID(), $custom_field2, true);
    $output2 .= (strlen($custom_field2_value) > 0 ? ‘

    ‘.$label.’: [embed width="640" height="360"]‘.$custom_field2_value.’[/embed]
    ‘ : ”);

    endforeach;
    return $output2;
    }

Viewing 3 replies - 1 through 3 (of 3 total)
  • cannot really tell you what’s wrong with this code since is not well formatted, do you want to use pastebin.com?
    Anyway the autoembed wordpress callback is hooked to the_content so.. probably your issue is that one.
    Do something like:
    return apply_filters('the_content', $output2); instead of
    return $output2;

    Thread Starter jabedbd

    (@jabedbd)

    @d4z_c0nf thanks bro. its works fine now ??

    Glad you solved man! ??

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Embed youtube from custom field value’ is closed to new replies.