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

  • Playwright now offers a UI mode

    #​631 — March 24, 2023 Read on the Web JavaScript Weekly Speeding Up the JavaScript Ecosystem: npm Scripts — The latest in what has been a fascinating series on finding ‘low hanging fruit’ when it comes to performance in the JavaScript world. The author explains it best himself: “‘npm scripts’ are executed by JavaScript developers

    Posted by Posted on March 24, 2023
    0
  • Everyone’s coming for Node.js this week

    #​479 — March 23, 2023 Read on the Web 🔒  npm Granular Access Tokens Now Generally Available — The granular access token feature on the npm registry is now generally available, allowing you to restrict token access to specific packages, set expiration dates, limit access by IP range, and more. GitHub Automatic npm Publishing with GitHub

    Posted by Posted on March 23, 2023
    0
  • Transformers: JavaScript in Disguise

    #​630 — March 17, 2023 Read on the Web JavaScript Weekly 🤖  Transformers.js: Running ML Models in the Browser — Transformers are a type of machine learning model often used for natural language or visual processing and while running such models directly in the browser is in its infancy, Transformers.js opens up some ML models

    Posted by Posted on March 17, 2023
    0
  • Shell-free scripting from Node

    #​478 — March 16, 2023 Read on the Web Shell-Free Scripts with Execa 7.1 — Execa is a popular process execution library for Node and the latest version includes an interesting $ method feature for writing zx-style scripts with it, making it even more useful for shell scripting style usecases. ehmicky Turbowatch: File Change Detector and

    Posted by Posted on March 16, 2023
    0
  • New JavaScript features of the past few years

    #​629 — March 10, 2023 Read on the Web JavaScript Weekly JavaScript Features from the Past Few Years — Packed with examples, this post tackles the changes and tweaks to JavaScript and TypeScript over the past several years (some as far back as ES6/ES2015, like tagged template literals). Linus Schlumberger Astro’s 2023 Web Framework Performance Report —

    Posted by Posted on March 10, 2023
    0
  • Taking flight with Feathers 5

    #​477 — March 9, 2023 Read on the Web Feathers 5: The API and Real-Time App Framework — Feathers isn’t as well known as Nest or Fastify, say, but it’s a powerful and mature option if you want to spin up a Node CRUD app tied to a database and now it’s “TypeScript all the

    Posted by Posted on March 9, 2023
    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
  • Playwright now offers a UI mode
  • Everyone’s coming for Node.js this week
  • Transformers: JavaScript in Disguise
  • Shell-free scripting from Node
  • New JavaScript features of the past few years
https://flatlogic.com/generator
COPYRIGHT © 2023 - Codepolice