• Resolved dambacher

    (@dambacher)


    Hello, can anyone see why this would not be working in a block? When I run this code in an ad inserter block, the page displays very strange and I get a critical error message. I’m trying to open random videos in wp lightbox after clicking and image. No other info.

    <?php
    function displayRandomVideoWithBanner() {
    
        // Define video URLs and banner image URL
        $video_urls = array(
            "https://www.youtube.com/watch?v=VideoId1",
            "https://www.youtube.com/watch?v=VideoId2",
            "https://www.youtube.com/watch?v=VideoId3"
        );
        $banner_image_url = "https://website.com/wp-content/uploads/2023/07/banner-image.png";
    
        // Shuffle the video URLs
        shuffle($video_urls);
    
        // Select the first video URL
        $random_video_url = array_shift($video_urls);
    
        // Check if a valid video URL is available
        if ($random_video_url) {
            // Create HTML output
    		echo "<a href='$random_video_url' rel='wp-video-lightbox'><img src='$banner_image_url' alt='alt text'></a>";
        } else {
            // If no valid video URL is available
            echo "Error: No valid videos found.";
        }
    }
    
    // Call to display the video and banner
    displayRandomVideoWithBanner();
    ?>

    I cant just use a simple [ADINSERTER ROTATE] because when I do, it doesn’t open the video in the wp lightbox, it just links directly to youtube.

    Thank you

Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Author Spacetime

    (@spacetime)

    In the preview window the code works fine so in principle it should work also when the page is generated and Ad Inserter called.

    You need to check the error message to diagnose the issue.

    Thread Starter dambacher

    (@dambacher)

    Are there error logs in ad inserter? I’ve just started working with it recently.

    Also, when I tried the rotate shortcode, instead of opening the videos in wp video lightbox, it links directly to the youtube page.

    So, this works:

    <a href="https://www.youtube.com/watch?v=VideoId" rel="wp-video-lightbox" title=""><img
    src="https://website.com/wp-content/uploads/2023/07/image.png" /></a>

    Bu, this does not:

    <a href="https://www.youtube.com/watch?v=VideoId" rel="wp-video-lightbox" title=""><img
    src="https://website.com/wp-content/uploads/2023/07/image.png" /></a>
    [ADINSERTER ROTATE]
    <a href="https://www.youtube.com/watch?v=VideoId" rel="wp-video-lightbox" title=""><img
    src="https://website.com/wp-content/uploads/2023/07/image.png" /></a>
    [ADINSERTER ROTATE]
    
    

    Thank you.

    Plugin Author Spacetime

    (@spacetime)

    The plugin can generate an insertion log:
    https://adinserter.pro/documentation/debugging

    But in your case it seems you have an issue with PHP code.

    Rotation simply randomly choses one of the options. If the Dynamic blocks are set to server-side then the code is inserted server-side. There should be no difference comparing to inserting the option code.

    If the Dynamic blocks are set to client-side insert then the selected code is inserted in the browser after the page is fully loaded.

    https://adinserter.pro/documentation/plugin-settings#dynamic-blocks

    BTW your rotation code is wrong – the last rotation option is empty. Maybe you only need to remove the last rotation separator.

    Thread Starter dambacher

    (@dambacher)

    Thanks, I tried the insert code several different ways. It just seems like when I use the rotate shortcode, it removes the rel attribute somehow and links directly to youtube. I’d rather just use the rotate code, but I couldn’t getit to work, so I tried a php solution. No go. Maybe I need to change the dynamic block config. I will try this a little later.

    Thread Starter dambacher

    (@dambacher)

    So, using this and setting the insertion for dynamic blocks to server side or client side show did the trick. Thank you for your help! Much appreciated.

    <a href="https://www.youtube.com/watch?v=VideoId" rel="wp-video-lightbox" title=""><img
    src="https://website.com/wp-content/uploads/2023/07/image.png" /></a>
    [ADINSERTER ROTATE]
    <a href="https://www.youtube.com/watch?v=VideoId" rel="wp-video-lightbox" title=""><img
    src="https://website.com/wp-content/uploads/2023/07/image.png" /></a>

Viewing 5 replies - 1 through 5 (of 5 total)

The topic ‘PHP not working in block’ is closed to new replies.