Tutorials / Third party compatibility

By default the plugin is compatible with several WordPress themes and can import videos from YouTube into posts that those themes can handle and embed videos. This is done by automatically filling post custom fields that are required by the themes to embed videos.

In case your theme isn’t in the compatible themes list (you can find the list in plugin menu, page Info & Help) you can follow this tutorial and make your theme compatible with the plugin. All the code needed for theme compatibility must be placed into your theme functions.php file.

We recommend using a child theme for this purpose otherwise you risk losing your changed when you update your theme.

Declare your theme as compatible (required)

First step is to tell the plugin that your theme is compatible with the plugin. To do this, use filter cbc_compatibility like this:

This tells the plugin that your theme is compatible with the plugin and that it should start listening to other filters.

Set the post type (required)

The next step is to tell the plugin what post type you want to use to import YouTube videos. To do this, use filter cbc_compatibility_post_type and return your post type name.

For example, if your theme uses regular post type to display videos, put this in your theme functions.php, right after the code from above:

Set post type category taxonomy

Next, you need to tell the plugin which taxonomy to use when importing videos. This is used for both setting existing categories and for importing categories retrieved from YouTube. If, at the previous step, you used post type post and you want to use default taxonomy category, you can skip this step.

To set the category taxonomy you can use filter cbc_compatibility_taxonomy and return the taxonomy name that you want to use. For our example, we will set this to category, even if it’s not necessary.

Set post type tag taxonomy

To import YouTube tags along with the videos you must set the tag taxonomy where these tags will be created. To do this, use filter cbc_compatibility_tag_taxonomy. Example below uses regular post post_tag taxonomy.

Autofill video URL into post custom field

If your theme needs the video URL to be provided into a custom field in order to embed the video, you must set the field using filter cbc_compatibility_url_meta. This will fill the video URL into the custom field that you specify and will allow your theme to embed the video.

Example below assumes that the theme needs a custom field named youtube_video_url to be filled with the video URL.

Autofill embed code into custom field

If instead of video URL your theme needs the video embed code to be placed into a custom field in order to be able to display the video, you can use filter cbc_compatibility_embed_meta.

Example below assumes that your theme needs custom field named youtube_embed_code to be filled with video embed code automatically.

Autofill video image into custom field

Some themes may require that you provide an URL to video image. To do this, use filter cbc_compatibility_image_meta and give the plugin the custom field name that you want the plugin to fill with the video image.

Example below assumes that image must be stored in custom field youtube_thumbnail.

Set post format

By default the plugin will set post format for imported videos to video. If you need a different post format for videos imported for your WordPress theme you can use filter cbc_compatibility_post_format.

Set theme name

When using theme compatibility, the plugin will display the theme name in various places. By default, the actual theme name of your theme (from styles.css) will be displayed. If you want to change the name displayed in plugin pages to anything else, use filter cbc_compatibility_theme_name.

Set theme URL

The plugin will also display links to your theme in various places in plugin. By default, the URL is taken from your theme details (from styles.css) but if you want to change that simply use filter cbc_compatibility_theme_url.


Example 1

First example assumes the following:

  1. import as post type post
  2. use default post category taxonomy
  3. use default post_tag taxonomy
  4. import video URL in custom field video_url

You may have noticed that we didn’t specify any category or tag taxonomies. The reason we didn’t do that is because for regular post type post, unless you specify a different category and/or tag taxonomy, the plugin will use default category and post_tag taxonomies.

Example 2

In this example we assume the following:

  1. import as post type portfolio
  2. use category taxonomy categories registered for post type portfolio
  3. use taxonomy category technologies registered for post type portfolio
  4. import video URL in custom field video_url

Related