Advanced Features

To use features described on this page, you will need a working knowledge of HTML and CSS, and of some knowledge of your blog’s internals.

Wrapping

If you want more control over the positioning or appearance of an embed, you can direct the plugin to wrap it in an HTML <div> or <span> with one or more CSS class names.

You can then create those CSS classes to modify the position and/or appearance of the embed.

To wrap an embed, Edit its settings and click on the checkbox in the Wrap Embed section of the settings page. This will reveal additional settings where you can select between using a <div> element or a <span> element as the wrapper, and specify one or more CSS class names to use with the wrapper. The class names are separated by a space character.

I used this feature to wrap the three social media buttons at the bottom of this page, so I could set a variety of CSS attributes to line them up a little better, and place one of them on the right hand side of the page.

Using a wrapper class is often preferable to inserting extra formatting code into the embed itself, especially if the embedded HTML has been provided by another web site. This is because at some point you may want to replace the embedded HTML with a more up-to-date version from the other site, and you may accidentally overwrite the changes you made and lose them.

However, there is only so much an wrapper can do, and you might find that you have to change the embedded code directly anyway (or perhaps add some direct CSS styling instead).

Calling User Functions

Occasionally you may want to do something with an embed that is not directly supported by the Embedder plugin. For example, you may want to embed the title of the current post, or only displayed an auto-embedded embed when the user is logged on.

This is where user functions come in. If you turn on the feature in an embed’s settings (Call User Function), you can specify the name of the function to be called whenever the embed is about to be added your blog’s content.

The PHP function is called before any of the attributes are processed, and must return the value of the embed to be added to the blog content. (That can be anything from the unmodified embed to an empty string.)

To be found by the Embedder plugin, the PHP function must exists somewhere in your blog’s code base. These types of functions are usually placed in your theme’s functions.php file or perhaps in another plugin created to hold a set of user functions for your blog.

The function takes four parameters:

$name: (string) the name of the embed
$value: (string) the value of the embed
$attrs: (array) array of attributes passed into the embed (name/value pairs)
$content: (string) the text between the embed’s begin and end tags (if any)

$attrs and $content may be null.

Here is an example of a user function that embeds various information about the current post:

function my_embed_post_info($name, $value, $attrs, $content) {
    global $post;
    if ($name == 'post-title') {
        $value = $post->post_title;
    } else if ($name == 'comment-count') {
        $value = $post->comment_count;
    } else if ($name == 'post-date') {
        $value = $post->post_date;
    }
    return $value;
}

The way this example is coded, you would create three different embeds (post-title, comment-count, and post-data) and specify the same user function for all of them.

Obviously, a better solution would be to create an embed called something like post-info and pass in a single attribute (say, type) which would tell the function which type of information about the post to embed:

function my_embed_post_info2($name, $value, $attrs, $content) {
    global $post;
    if (!empty($attrs) && !empty($attrs['type'])) {
        switch ($attrs['type']) {
            case'post-title':
               $value = $post->post_title;
               break;
            case 'comment-count':
               $value = $post->comment_count;
               break;
            case 'post-date':
               $value = $post->post_date;
               break;
        }
    }
    return $value;
}

You may have noticed that using a user function with an embed essentially turns the embed into a normal WordPress shortcode. Indeed, you can use this feature of the Embedder plugin to manage all your normal shortcodes if you want, with the additional benefit of the extra features like attribute substitution, auto-embeds, and wrapping.