WordPress Plugin: Enhanced Text Widget

0
809
Wordpress Enhanced Text Widget

If you are looking for an all purpose text widget, the Enhanced Text Widget will do the trick.

So here was my problem. In my sidebar, I needed to have rendered several ads represented in HTML. I also had a Google Adsense Javascript ad that is to be placed in the sidebar too.

Looking in my widget toolbox, I had several widgets available that were highly specific to the task. One was an HTML and text widget. Another, an ads box widget that only took Javascript.
So I went out and dropped both of them in the sidebar.

Ugly!

The problem is, each widget is it’s own DIV container and is left to the mercy of the theme in how each is rendered. In my case, some big honking margin and padding spaces that you can drive a truck through.

No, I didn’t really want to fiddle with it and create custom CSS for the theme.

The Enhanced Text Widget Plugin

So I went searching for an all purpose text widget and found one that is very flexible and supports all these code types:

  • Javascript
  • Html
  • Text
  • CSS
  • Php
  • Flash
  • Shortcodes

I quickly looked through the source code to see that this plugin is very small. All the hard work is done through a get_short_code and PHP eval() call.

// Parse the text through PHP
ob_start();
eval('?>' . $text);
$text = ob_get_contents();
ob_end_clean();
 
// Run text through do_shortcode
$text = do_shortcode($text);
</php>

The use of eval() can be dangerous so make sure you understand what you are doing when using this plugin. The important thing to watch out for is to never submit user input to the eval function as an argument. If you do, a hacker can insert PHP code and wreak havoc. Since the Enhanced Text Widget is not taking in any user input in my use of it, it is safe to use.

A Practical Example

Let’s build something useful. How about this to get you monetizing your blog.
Enhanced text widget

A good place to stick ads is in your sidebar. Most WordPress themes have a sidebar where you can drop WordPress widgets into. Go ahead and drop the Enhanced Text Widget into the sidebar.
Enhanced text widget

The CSS

<style>
.sidebar-ad {
  float: left;
  margin: 0 1em 1em 0;
  max-width: 135px;
}
 
.sidebar-google {
  margin: 0 1em 1em 0;
  max-width: 100%;
}
.sidebar-google iframe {
  height: inherit !important;
}
</style>

The HTML

<div class="sidebar-ad">
  <!-- anchor tag code to A Small Orange -->
</div>
<div class="sidebar-ad">
  <!-- anchor tag code to Theme Forest -->
</div>
<div class="sidebar-google">
  <!-- javascript code to Adsense ad -->
</div>

Cut/paste the code above and feel free to adapt it to your own personal WordPress blog.

Of Interest