Easy Embed WordPress Plugin

The WordPress editor doesn’t always play nice with HTML (especially if you switch back and forth between the Visual and HTML editor). This problem has bugged me for a while, and I finally sat down and built a simple plugin to solve it. There are other solutions out there, but I find this method to be the easiest to use. After installing the plugin, all that is required is to create a custom field (you can name it anything), place your code in the new custom field. This could be HTML, video embed codes, Paypal forms, etc. Then place the following shortcode into your post where you want your special code to go:

The field property should be the name of the custom field you created. The shortcode above would display the contents of a custom field with the name “easy”

Download Easy Embed from the WordPress plugin directory.

View the code below:

<?php

/*
Plugin Name: Easy Embed
Plugin URI: http://wordpress.org/#
Description: Allows the embedding of any code and protects it from being modified by the WordPress editor
Author: Alex Mansfield
Version: 1.0
Author URI: https://alexmansfield.com/
*/

function am_easy_embed($array) {
extract(shortcode_atts(array('field' => 'custom'), $array));
global $post;
$html = get_post_meta($post->ID, $field, true);
return $html;
}
add_shortcode('easyembed', 'am_easy_embed');

?>
Posted in

9 thoughts on “Easy Embed WordPress Plugin”

  1. Hi Alex, I have been struggling and giving up again for years trying to get html code such as a paypal shopping cart button code into my wordpress. WordPress is a nightmare editor stripping html every time I switch views… and then I find your plugin.. very simple and yet ingenious!!

    Thank you so much for creating this 🙂

Leave a Comment

Your email address will not be published. Required fields are marked *