Site icon Hip-Hop Website Design and Development

static variable loop not working in WordPress

I’ve a operate in my wordpress theme that deletes the primary embedded video in a video submit. See code under. That is within the features.php file.

/* - operate that hides first video in submit content material - */

operate process_embed( $embed ){

    if ( is_single() && get_post_format() === 'video' ) {
        static $post_video_num = 0;

        $post_video_num++;

        // Disguise first video within the submit content material on single video submit web page
        if ( 1 === $post_video_num ) {
            return '';
        }
    }

    return $embed;
}


add_filter( 'embed_oembed_html', 'process_embed', 10, 3 );
add_filter( 'video_embed_html', 'process_embed' ); // Jetpack

As you may see, if the submit is a single submit and it is a video format, it would declare a static variable and iterate it everytime a video is within the submit. If the static variable $post_video_num is 1 (that means the primary video within the submit) it’s changed with clean, eradicating the primary embed video.

This code works superb in my development setting on my native machine. Nonetheless, it does not appear to work on my dwell server. That’s the downside.

Whereas I used to be debugging, after echoing out the $post_video_num variable, I discovered that it will not take away the primary video as a result of the variable $post_video_num is 8 (as a substitute of 1, appropriately).

After echoing out the $post_video_num numbers, what is going on is that it echoes out the numbers 1-8 on prime of the web page, then echoes out 8-12 instead of the place the primary video needs to be. Particularly on the dwell server, the operate appears to loop a number of occasions, which is why it does not work.

The core downside, which is what’s puzzling me, is that this operate works as supposed on my native machine however not on the dwell server, because it does this unusual looping factor which I can not clarify.

What would trigger this operate to work on my native machine and never the dwell server? Is there one thing I’m lacking right here?

Thanks! I hope this is smart. You are assistance is significantly appreciated.