Auto Embeds

Another useful feature of the Embedder plugin is the ability to make an embed appear automatically (i.e. without you having to input it yourself) in certain places in your blog.

In the current version of the plugin, this is limited to the start or end of a blog post or blog page. For example, the social media buttons (Twitter, Facebook, etc.) you see at the bottom of the posts in this blog are auto-embedded by the plugin.

To use this feature, simply select one or more places where you want to the embeds to appear in the Auto Embed section of your embed’s settings page, and save the settings. The embed should immediately begin appearing in the place(s) you selected.

Embed Priority

If you specify more than one embed to appear in the same place, you can control the order in which they appear by setting their priorities. The lower the number, the higher the priority, and the embed with the highest priority is always embedded first.

For example, if three embeds have the priorities of 10, 40, and 5, they will appear in the following order of priority: 5, 10, 40.

Including and Excluding Embeds

If you only want an auto-embed to appear on a specific set of pages or posts, you can use the Include/Exclude options to limit where the embeds will appear. You can include and/or exclude auto-embeds based on a post’s categories or tag, and for pages, you can also selectively place your embeds depending on the parent of the page.

(Note: the standard WordPress interface does not allow you to set categories or tags for pages, but if you use another plugin to add that support, the Embedder plugin will also support them.)

To specify a category or tag to exclude/include, simply enter its name (or slug) into the appropriate text box. Multiple values should be separated by commas.

(Note: do not use tag or category names that have commas in them, because that will confuse the plugin. You can use the tag or category’s slug instead. See below for more details.)

Examples:

If you only want to auto-embed the Facebook “Like” button into specific blog posts, you can tag those posts with the tag called, say, like-this and add it to the Include Tags field in the settings page for the auto-embed.

But if you want to add the Facebook “Like” button to all your posts, except a few (e.g. posts that are just administrative announcements) you can tag the posts you want to exclude with something like no-like-button and add the tag name to the Exclude Tags field in the settings page.

This section of the moztools website includes page-back and page-forward links on every page to make it easier to navigate the documentation. These are all generated by one auto-embed (that calls a user-function) called subpage-links.

But I don’t want these links on every page of the site, so in the Include Page Parents field in the settings page I have added to the parent page’s slug (embedder-plugin) to restrict the navigation links to this part of the website.

Of course, if I create another plugin, I may want to use the subpage-links embed there too, and all I need to do to do this is add the new parent page to the Include Page Parents settings.

Rules for Including and Excluding Embeds

What is included and excluded can get a little complicate, so here are the basic rules the plugin uses for auto-embedding.

Specifying Tags:

  • To specify a tag, use the tag name or tag slug. A list of all the tags you are using can be found using the Posts >> Post Tags page.

Specifying Categories:

  • To specify a category, use the category name or category slug. A list of all the categories in your blog can be found using the Posts >> Categories page.
  • Categories can have other categories as children. When you include or exclude a category, you are including/excluding all its children and other descendants too). For example, if movies is the parent category, and animation is a child of movies, including movies will include all posts in the animation category as well.
  • You can use this capability to exclude posts in certain child categories. For example, if you don’t want the above auto-embed to appear in posts about documentary movies, you can include the movies category but exclude the documentaries child category. The auto-embed will appear in all other child categories of the parent category movies, but not documentaries.

Specifying Parent Pages:

  • To specify a parent page, use the parent page’s slug or id. To find those, edit the parent page in WordPress and look at the highlighted part of the Permalink displayed at the top of the page. The page id will also displayed in the browser’s address bar (after ?post=).
  • To specify top level pages with no parents, use 00 (double-zero).

Rules:

  • You can specify as many tags/categories/or parent pages as you want, separated by commas.
  • Do not use category or tag names that have commas in them. Use their slugs instead.
  • You can specify any combination of pages, tags, and categories to get the desired result, but they will always be processed in the following order:
    • Parent page includes (if the embed is in a page)
    • Parent page excludes (if the embed is in a page)
    • Category includes
    • Category excludes
    • Tag includes
    • Tag excludes
  • Thus, you can include a parent category, and exclude one of its children, but you cannot exclude a parent category then include one of its children. (Excluding the parent will also exclude its children.)
  • In most cases you will only need to include one or two things, or perhaps exclude them, which should keep things simple enough.
  • If you can’t get the desired result, however, you can always use two or more copies of the same embed to get what you need.
  • Finally, it’s important to remember that the includes/excludes settings only apply to auto-embedded embeds. You can always manually insert the shortcodes for your embeds exactly where you need them, and you can even use them in conjunction with other template-related plugins, if necessary.

Notes on Auto Embeds

You can always use auto-embeds as ordinary embeds whenever and wherever you need them.

You only need to set an embed’s priority if you are auto-embedding more than one embed in the same location. Otherwise, the priority setting is not used (even if it is displayed in the settings pages).

If two auto-embedded embeds in the same location have the same priority, the order in which they are displayed is undefined.

You cannot use attributes with auto-embedded embeds, because there is no way to pass them to the embed.

Some embeds may not work if they are embedded more than once on the same page. This is entirely up to the HTML code or scripts you are embedding, and there is nothing the plugin can do about it.