WordPress.org

Ready to get started?Download WordPress

Forums

[Plugin: Subscribe Widget] Great, but could use some code improvements (2 posts)

  1. Mattias Buelens
    Member
    Posted 5 years ago #

    First of all, I love this plugin. It's terribly easy to use and it does just want I need: display some nice subscribe icons. However, from a developer's point of view, I think you could improve your code a little bit to make life easier for other theme/plugin developers.

    Currently, at plugin version 1.1.0, you have hard-coded the HTML around the widget like this:

    if( $title != '' ){
        echo '<h2>'.$title.'</h2>';
    }
    echo '<div id="subscribe-widget">';
    // ...
    echo '</div>';

    Although this will work fine in many cases, it's not very good practice. For example: when the widgets are placed in an <ul> as individual <li> elements, the <div> breaks (X)HTML-validity. Also, not everyone theme uses <h2> for widget titles, <h3> is also a common choice.

    Therefore I suggest to make use of the arguments provided by WordPress's widget engine: before_widget, after_widget, before_title and after_title. This will not only make the output valid HTML, it gives much more flexibility and consistency to the theme developer!

    echo $before_widget;
    if( $title != '' ){
        echo $before_title . $title . $after_title;
    }
    // ...
    echo $after_widget;

    Note: I placed $before_widget before the title, as it's better and more consistent to have your #subscribe-widget contain the title element too.

    Hopefully you can do something with my suggestions and keep up the good work!

    - Mattias.

  2. Mattias Buelens
    Member
    Posted 5 years ago #

    It appears this problem was solved in version 1.1.2. Beautiful! :)

Topic Closed

This topic has been closed to new replies.

About this Topic