Skip to content

Instantly share code, notes, and snippets.

@devinsays
Created June 15, 2015 22:49

Revisions

  1. devinsays created this gist Jun 15, 2015.
    42 changes: 42 additions & 0 deletions efficient-fitvids.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,42 @@
    /**
    * Enqueue theme scripts
    */
    function prefix_scripts() {

    // FitVids Script conditionally enqueued from inc/extras.php
    wp_register_script(
    'prefix-fitvids',
    get_template_directory_uri() . '/js/jquery.fitvids.min.js',
    array( 'jquery' ),
    '1.0.0',
    true
    );

    }
    add_action( 'wp_enqueue_scripts', 'prefix_scripts' );

    /**
    * Enqueues FitVids, since the embed might be a video.
    *
    * @since 1.0.0.
    *
    * @param string $html The generated HTML of the embed handler.
    * @param string $url The embed URL.
    * @param array $attr The attributes of the embed shortcode.
    *
    * @return string Returned HTML.
    */
    function prefix_embed_container( $html, $url, $attr ) {
    // Bail if this is the admin
    if ( is_admin() ) {
    return $html;
    }

    if ( isset( $attr['width'] ) ) {
    wp_enqueue_script( 'prefix-fitvids' );
    }

    return $html;
    }
    add_filter( 'embed_handler_html', 'prefix_embed_container', 10, 3 );
    add_filter( 'embed_oembed_html' , 'prefix_embed_container', 10, 3 );