Home Forums ACF PRO Can't display oEmbed in Widget


Can't display oEmbed in Widget

  • I’ve created a simple widget and added the oEmbed custom field to that widget to display a youtube video.

    I have a conditional check but it keeps retuning ‘No Video’, instead of displaying the video.

    Any ideas what the issue could be? I have tripled checked the field slug etc

    	public function widget( $args, $instance ) {
    		echo $args['before_widget'];
    		if ( ! empty( $instance['title'] ) ) {
    			echo $args['before_title'] . apply_filters( 'widget_title', $instance['title'] ) . $args['after_title'];
    		//echo __( esc_attr( 'Hello, World!' ), 'text_domain' );
    		if ( get_field( 'youtube_share_url', 'widget_' . $widget_id ) ) :	
    			echo the_field( 'youtube_share_url', 'widget_' . $widget_id );	
    			echo 'Video Present.';
    		else :
    			echo 'No Video.';
    		echo $args['after_widget'];
  • in your code $widget_id has no value. I’m not sure where to get it from in this context but it should be an argument in either $args or $instance. I’ve done some looking, and even looking and it’s hard to tell I think it may be $instance->id but I’m not sure

  • Got it!

    the_field( 'youtube_share_url', 'widget_' . $args['widget_id']

  • I’ll need to remember that. I’ve built a few widgets, just not with ACF yet.

Viewing 4 posts - 1 through 4 (of 4 total)

The topic ‘Can't display oEmbed in Widget’ is closed to new replies.