Skip to content

Codepolice

  • ⤫

Creating an empty/blank text widget for WordPress without additional markup and divs

Posted by Judy Alvarez Posted on February 28, 2022March 1, 2022
0

WordPress provides a simple text widget that you can use on your blog to add some random HTML, Ads, images, and so on. But I have one problem and that is that it’s always adding some extra HTML like this.

<div class="widget">
 <div class="textwidget">
 </div>
</div>

Sometimes you do not want this code if you for example want to add a widget to a ul and want the outer tag to be a li. I tried to Google for this but surprisingly I didn’t find a single “Super Empty Text Widget” so I created one myself.

/**
 * SuperEmptyWidget Class
 */
class SuperEmptyWidget extends WP_Widget {
    /** constructor */
    function SuperEmptyWidget() {
        parent::WP_Widget(false, $name = 'SuperEmptyWidget');
    }

    /** @see WP_Widget::widget */
    function widget($args, $instance) {
        extract( $args );
        $content = $instance['content'];
        echo $content;
    }

    /** @see WP_Widget::update */
    function update($new_instance, $old_instance) {
	$instance = $old_instance;
	$instance['content'] = $new_instance['content'];
        return $instance;
    }

    /** @see WP_Widget::form */
    function form($instance) {
        $content = esc_attr($instance['content']);
        ?>
         <p>
          <label for="<?php echo $this->get_field_id('content'); ?>"><?php _e('Content:'); ?></label>
		          </p>
          <textarea class="widefat" cols="20" rows="16" id="<?php echo $this->get_field_id('content'); ?>" name="<?php echo $this->get_field_name('content'); ?>"><?php echo $content; ?></textarea>

        <?php
    }

} // class SuperEmptyWidget

// register SuperEmptyWidget widget
add_action('widgets_init', create_function('', 'return register_widget("SuperEmptyWidget");'));

Just add that to your functions.php and you should have a widget that does not add any crap either before or after the content.

Categories: JavascriptTagged: best free wordpress themes, cpanel wordpress, descargar wordpress, free wordpress templates, how to install wordpress, how to use wordpress, htaccess wordpress, localhost/wordpress/wp-login.php, plugins wordpress, themes wordpress, wordpress backup, wordpress dashboard, wordpress divi, wordpress docker, wordpress free, wordpress free themes, wordpress gratis, wordpress gutenberg, wordpress install, wordpress rest api, wordpress support, wordpress templates free, wordpress woocommerce, wordpress テーマ

Post navigation

Previous Previous post: IE9 mess up the color theme in Visual Studio when started
Next Next post: Entity Framework Scaffolding: The type is not mapped issue

Related Posts

  • A Bun-believable release that isn’t half-baked

    #​757 — October 17, 2025 Read on the Web JavaScript Weekly Bun 1.3: The Full-Stack JavaScript Runtime — Arriving a few hours after last week’s issue (natch!) Bun 1.3 remains the big news of the past week. Bun is a performance and DX-focused JavaScriptCore-powered runtime which, with v1.3, balances being a drop-in Node.js replacement with

    Posted by Posted on October 17, 2025
    0
  • Bringing Python apps into Node

    #​596 — October 14, 2025 Read on the Web 📂 A Modern Guide to Reading and Writing Files in Node — A comprehensive guide to various methods for working with files, from promise-based methods through to working with streams, processing files concurrently, using file handles, and memory-efficient techniques. Luciano Mammino A Way to Integrate Python ASGI with Node.js

    Posted by Posted on October 14, 2025
    0
  • Vite gets its own documentary

    #​756 — October 10, 2025 Read on the Web JavaScript Weekly ▶  Vite: The Documentary — From the same creators of the fantastic ▶️ Node.js, ▶️ Angular and ▶️ React documentaries comes an up to date look at Vite, the build tool that has taken the JavaScript ecosystem by storm in recent years. Many luminaries make an appearance to

    Posted by Posted on October 10, 2025
    0
  • npm security best practices to consider

    #​595 — October 7, 2025 Read on the Web 15 Recent Node Features That Can Replace Popular npm Packages — Many features that once required third-party packages are now built into the runtime itself. Here’s a look at some of the most notable that you may want to experiment with, prior to reducing unnecessary dependencies. Lizz

    Posted by Posted on October 7, 2025
    0
  • React 19.2 is in the building

    #​755 — October 3, 2025 Read on the Web JavaScript Weekly The State of JavaScript 2025 Survey — Each year, Devographics runs an epic survey of as many JavaScript community members as it can and turns the results into an interesting report on the state of the ecosystem – here’s the results from 2024. If

    Posted by Posted on October 3, 2025
    0
  • Using Node with Cloudflare Workers

    #​594 — September 30, 2025 Read on the Web 🗓️ We’re back after taking a week off for my birthday. I’ve never bothered to do that before, but I figured I’d give it a go, and.. it was good 😅 We’re now back every week until Christmas!__Peter Cooper, your editor A Year of Improving Node.js

    Posted by Posted on September 30, 2025
    0
Judy Alvarez

Leave a Reply Cancel reply

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

Codepolice

  • Github
  • Atlassian
  • Flatlogic
  • Xero
  • Jetbrains
  • Figma
  • A Bun-believable release that isn’t half-baked
  • Bringing Python apps into Node
  • Vite gets its own documentary
  • npm security best practices to consider
  • React 19.2 is in the building
https://flatlogic.com/generator
COPYRIGHT © 2025 - Codepolice