Implementing Vimeo Video Gallery in Your Plugin

Posted on 17th June 2023

As a WordPress plugin developer, you may be asked to add a Vimeo video gallery to a plugin. This can be accomplished by following a few simple steps.

Step 1: Register a Vimeo Developer Account

In order to access the Vimeo API, you will need to register for a Vimeo Developer account. Once you have registered for an account, you will be able to create an application. For your application, you will need to specify the following information:

  • The name of your application
  • A description of your application
  • The website URL for your application
  • The callback URL for your application

The callback URL is the URL that Vimeo will redirect to after a user has granted your application access to their account. For example, if your website is example.com, you could set your callback URL to example.com/vimeo-callback.php.

Step 2: Generate an Access Token

Once you have registered your application, you will need to generate an access token. An access token is required in order to make calls to the Vimeo API. To generate an access token, you will need to send a POST request to the following URL:

https://api.vimeo.com/oauth/authorize/client

You will need to include the following parameters in your request:

  • grant_type: This should be set to client_credentials
  • scope: This should be set to public

You will also need to include your Vimeo Developer application’s client ID and client secret in the request header. The client ID and client secret can be found in your application’s settings on the Vimeo Developer website.

If your request is successful, you will receive a JSON response that contains your access token. This access token will need to be included in all future requests to the Vimeo API.

Step 3: Make a Request to the Vimeo API

Once you have generated an access token, you can start making requests to the Vimeo API. For this example, we will be making a request to the /videos endpoint. This endpoint returns a list of videos that the authenticated user has access to.

To make a request to the Vimeo API, you will need to send a GET request to the following URL:

https://api.vimeo.com/videos

You will need to include the following parameters in your request:

  • per_page: This is the number of videos that you want to receive per page. The maximum value for this parameter is 100.
  • page: This is the page number of the results that you want to receive. The default value for this parameter is 1.

You will also need to include your access token in the request header.

If your request is successful, you will receive a JSON response that contains a list of videos. Each video in the list will include information such as the video’s title, description, duration, etc.

Step 4: Display the Videos in a Gallery

Once you have retrieved the list of videos from the Vimeo API, you can display them in a gallery on your website. For this example, we will be using the wp_enqueue_script() function to load the Vimeo player JavaScript library and the wp_enqueue_style() function to load the Vimeo player CSS file.

We will also be using the WordPress loop to loop through each video in the list and output the video’s title, description, and thumbnail image.

Here is the code that you will need to add to your plugin:

// Load the Vimeo player JavaScript library.
wp_enqueue_script( 'vimeo-player', 'https://player.vimeo.com/api/player.js', array(), '1.0.0', true );

// Load the Vimeo player CSS file.
wp_enqueue_style( 'vimeo-player', 'https://player.vimeo.com/api/player.css', array(), '1.0.0' );

// Retrieve the list of videos from the Vimeo API.
$videos = vimeo_get_videos();

// Loop through each video in the list.
foreach ( $videos as $video ) {
    // Output the video's title, description, and thumbnail image.
    echo '<h2>' . $video['title'] . '</h2>';
    echo '<p>' . $video['description'] . '</p>';
    echo '<img src="' . $video['thumbnail_url'] . '" alt="' . $video['title'] . '" />';
}

And that’s it! You have now successfully implemented a Vimeo video gallery in your WordPress plugin.

Now that you have your Vimeo API key, you need to create a new Vimeo gallery. To do this, log in to your WordPress site and go to Vimeography → Add New. Give your gallery a name and select the Vimeo albums you want to display.

You can also choose to display your Vimeo gallery in a lightbox. To do this, select the Lightbox checkbox. When you’re finished, click the Publish button.

Now that you’ve created your Vimeo gallery, it’s time to add it to your WordPress site. To do this, log in to your WordPress site and go to the page or post where you want to display the gallery. Then, click the Add Media button.

In the Insert Media window, click the Vimeography tab. Then, select the Vimeo gallery you want to insert and click the Insert Gallery button.

Your Vimeo gallery will now be displayed on your WordPress site.

Once you have your Vimeo video gallery set up, you can start displaying your videos on your WordPress site.

To do this, you’ll need to add a shortcode to your WordPress post or page.

The shortcode you’ll need to use is:

[vimeo-gallery]

You can then add the URL of the Vimeo video you want to display in the shortcode.

For example, if you wanted to display the video with the URL https://vimeo.com/123456789, you would use the following shortcode:

[vimeo-gallery url=”https://vimeo.com/123456789″]

You can also add multiple videos to your gallery by separating the URLs with a comma.

For example, if you wanted to display two videos, you would use the following shortcode:

[vimeo-gallery url=”https://vimeo.com/123456789,https://vimeo.com/987654321″]

You can also add a title to your video gallery by using the “title” attribute in the shortcode.

For example, if you wanted to add a title to your gallery, you would use the following shortcode:

[vimeo-gallery title=”My Vimeo Gallery”]

You can also add a description to your video gallery by using the “description” attribute in the shortcode.

For example, if you wanted to add a description to your gallery, you would use the following shortcode:

[vimeo-gallery description=”My Vimeo Gallery Description”]

You can also specify the number of videos you want to display in your gallery by using the “count” attribute in the shortcode.

For example, if you only wanted to display two videos in your gallery, you would use the following shortcode:

[vimeo-gallery count=”2″]

If you want to display more than two videos in your gallery, you can use the “offset” attribute to specify the number of videos you want to skip.

For example, if you wanted to display four videos in your gallery, but you only wanted to display the first two, you would use the following shortcode:

[vimeo-gallery offset=”2″]

You can also specify the width and height of your video gallery by using the “width” and “height” attributes in the shortcode.

For example, if you wanted to display your gallery at a width of 600 pixels and a height of 400 pixels, you would use the following shortcode:

[vimeo-gallery width=”600″ height=”400″]

You can also specify the alignment of your video gallery by using the “align” attribute in the shortcode.

For example, if you wanted to align your gallery to the left, you would use the following shortcode:

[vimeo-gallery align=”left”]

If you want to align your gallery to the right, you would use the following shortcode:

[vimeo-gallery align=”right”]

If you want to center your gallery, you would use the following shortcode:

[vimeo-gallery align=”center”]

You can also specify whether you want your video gallery to be responsive by using the “responsive” attribute in the shortcode.

If you want your gallery to be responsive, you would use the following shortcode:

[vimeo-gallery responsive=”true”]

If you don’t want your gallery to be responsive, you would use the following shortcode:

[vimeo-gallery responsive=”false”]

You can also specify whether you want your video gallery to display the title and description of each video by using the “showinfo” attribute in the shortcode.

If you want your gallery to display the title and description, you would use the following shortcode:

[vimeo-gallery showinfo=”true”]

If you don’t want your gallery to display the title and description, you would use the following shortcode:

[vimeo-gallery showinfo=”false”]

You can also specify whether you want your video gallery to display the Vimeo logo by using the “logo” attribute in the shortcode.

If you want your gallery to display the Vimeo logo, you would use the following shortcode:

[vimeo-gallery logo=”true”]

If you don’t want your gallery to display the Vimeo logo, you would use the following shortcode:

[vimeo-gallery logo=”false”]

You can also specify whether you want your video gallery to display the Vimeo player controls by using the “controls” attribute in the shortcode.

If you want your gallery to display the Vimeo player controls, you would use the following shortcode:

[vimeo-gallery controls=”true”]

If you don’t want your gallery to display the Vimeo player controls, you would use the following shortcode:

[vimeo-gallery controls=”false”]

You can also specify whether you want your video gallery to display the Vimeo video title by using the “showtitle” attribute in the shortcode.

If you want your gallery to display the Vimeo video title, you would use the following shortcode:

[vimeo-gallery showtitle=”true”]

If you don’t want your gallery to display the Vimeo video title, you would use the following shortcode:

[vimeo-gallery showtitle=”false”]

You can also specify whether you want your video gallery to display the Vimeo video byline by using the “showbyline” attribute in the shortcode.

If you want your gallery to display the Vimeo video byline, you would use the following shortcode:

[vimeo-gallery showbyline=”true”]

If you don’t want your gallery to display the Vimeo video byline, you would use the following shortcode:

[vimeo-gallery showbyline=”false”]

You can also specify whether you want your video gallery to display the Vimeo video portrait by using the “showportrait” attribute in the shortcode.

If you want your gallery to display the Vimeo video portrait, you would use the following shortcode:

[vimeo-gallery showportrait=”true”]

If you don’t want your gallery to display the Vimeo video portrait, you would use the following shortcode:

[vimeo-gallery showportrait=”false”]

You can also specify whether you want your video gallery to display the Vimeo video color by using the “color” attribute in the shortcode.

If you want your gallery to display the Vimeo video color, you would use the following shortcode:

[vimeo-gallery color=”ffffff”]

If you don’t want your gallery to display the Vimeo video color, you would use the following shortcode:

[vimeo-gallery color=”000000″]

You can also specify whether you want your video gallery to be fullscreen by using the “fullscreen” attribute in the shortcode.

If you want your gallery to be fullscreen, you would use the following shortcode:

[vimeo-gallery fullscreen=”true”]

If you don’t want your gallery to be fullscreen, you would use the following shortcode:

[vimeo-gallery fullscreen=”false”]

You can also specify whether you want your video gallery to loop by using the “loop” attribute in the shortcode.

If you want your gallery to loop, you would use the following shortcode:

[vimeo-gallery loop=”true”]

If you don’t want your gallery to loop, you would use the following shortcode:

[vimeo-gallery loop=”false”]

You can also specify whether you want your video gallery to autoplay by using the “autoplay” attribute in the shortcode.

If you want your gallery to autoplay, you would use the following shortcode:

[vimeo-gallery autoplay=”true”]

If you don’t want your gallery to autoplay, you would use the following shortcode:

[vimeo-gallery autoplay=”false”]