Forums

[Plugin: Shadowbox JS] Convert YouTube links to proper format? (2 posts)

  1. Hesadanza
    Member
    Posted 1 month ago #

    All of the YouTube links on my blog are directed to the YouTube video page, not directly to the videos. Can the Shadowbox plugin automatically convert the links from the format "watch?v=" to "v/" so that they will play within the Shadowbox? Perhaps it could be given as an option in the settings? Right now if you click on these links, an empty shadow box appears.

  2. sivel
    Member
    Posted 1 month ago #

    The Shadowbox JS plugin does not automatically do this. Could it? Yes. Will it? Possibly.

    This code placed in a new plugin or in your themes functions.php should work. Note: This code is untested.

    <?php
    function yt_sbox($content='') {
        return preg_replace('%youtube\.com/watch\?v=([^\&]+)%', 'youtube.com/v/$1', $content);
    }
    add_filter('the_content', 'yt_sbox', 9, 1);
    ?>

Reply

You must log in to post.

About this Topic