• Resolved James Revillini

    (@jrevillini)


    This was reported already here but the solution wasn’t ideal because the suggested code actually prints the output directly and returns nothing. This can give the semblance of things working properly depending on setup, but it actually prints the content of the excerpt generated by Advanced Excerpt outside the designated container div.uagb-post__text.uagb-post__excerpt (and this can lead to weird display/CSS stuff).

    I tried amending the suggested code by calling the_advanced_excerpt() the correct way as seen here:

    add_filter('uagb_single_post_excerpt_grid', function($excerpt, $id, $attr) {
        return the_advanced_excerpt( '', true ) ;
    },10, 3 );

    This fixed the output so it goes inside the proper div.uagb-post__text.uagb-post__excerpt , but this caused videos to go missing again.

    After some debugging, I found that the output while in my hook above does contain the iframe with the YouTube video, but it gets stripped from output before printing on the page.

    I have nothing else on my site that would alter the output of the excerpt, and I’ve switched to default themes to double-check, so this leads me to believe that Spectra is further refining output of the excerpt without giving us any option to turn it off. I looked at your docs but I also don’t see a way to programmatically disable further filtering.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter James Revillini

    (@jrevillini)

    I jumped the gun. Spectra itself doesn’t alter the excerpt further, but wp_kses_post() does, and Spectra implements this function to output the post excerpt in the post grid block.

    For future readers, my final code snippet included someone else’s solution to allow iframes in the output from wp_kses_post:

    /**
     * Add iFrame to allowed wp_kses_post tags
     *
     * @param array  $tags Allowed tags, attributes, and/or entities.
     * @param string $context Context to judge allowed tags by. Allowed values are 'post'.
     *
     * @return array
     */
    function custom_wpkses_post_tags( $tags, $context ) {
    
        if ( 'post' === $context ) {
            $tags['iframe'] = array(
                'src'             => true,
                'height'          => true,
                'width'           => true,
                'frameborder'     => true,
                'allowfullscreen' => true,
            );
        }
    
        return $tags;
    }
    
    add_filter( 'wp_kses_allowed_html', 'custom_wpkses_post_tags', 10, 2 );
    
    add_filter('uagb_single_post_excerpt_grid', function($excerpt, $id, $attr) { 
    	$content = the_advanced_excerpt( '', true ) ;
    	return $content;
    },10, 3 );
    
    Plugin Support mohsinbsf

    (@mohsinbsf)

    Hi @jrevillini,

    Thank you for sharing the workaround with us!

    If you need anything else we can help you with, don’t hesitate to open a new ticket.

    Have a nice day!

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘youtube videos stripped from post grid even using Advanced Excerpt function’ is closed to new replies.