• hp3

    (@hp3)


    I am creating a theme and need to add <hr /> tag after the title and before the listing of each widget that appears in the sidebar.

    My goal is to enable someone using the theme to add any number of widgets to the sidebar from the appearance menu in the back end and each widget will display in the blog with a <hr /> after the title.

    Is there a dynamic way I can modify the html stored in the “after_title” argument of each active widget to insert a <hr /> tag after the title?

    Also I need to change the wording of the search form widget submit button to “Go” instead of “Search”. I’ve done this by creating a searchform.php template file and building my own form with a submit button with value “Go”. I also added <hr /> after the title of the search widget.

    Will this be a problem for any dynamic solution that adds <hr /> to each widget?

Viewing 2 replies - 1 through 2 (of 2 total)
  • Michael

    (@alchymyth)

    need to add <hr /> tag after the title

    register_sidebar() in functions.php;

    http://codex.wordpress.org/Function_Reference/register_sidebar

    'after_title' => '</h2><hr />'

    (untested)

    Also I need to change the wording of the search form widget submit button to “Go” instead of “Search”.

    try a filter function added to functions.php of your theme:
    for instance:

    add_filter('get_search_form', 'new_search_button');
    function new_search_button($text) {
    $text = str_replace('value="Search"', 'value="Go"', $text);
    return $text;
    }

    I also added <hr /> after the title of the search widget.

    Will this be a problem for any dynamic solution that adds <hr /> to each widget?

    you may end up with two <hr /> after the search.

    Thread Starter hp3

    (@hp3)

    Thanks, both of these suggestions worked except for adding the <hr /> to the search form title.

    I first removed searchform.php template from my theme files. Then I modified the code in the functions.php as you suggested. This added the <hr /> after all widget titles in the primary side bar, except the title of the default search form.

    The filter replaced the wording of the button “search” with “go”. I added a second string_replace in the filter to reword the Search form widget title and add a <hr />.

    However, I am wondering what is different about the search form widget that the title did not include <hr /> tag, eventhough I modified the after_title argument to include the <hr />, while the other widget titles correctly did include the <hr />. I had to resort to a search_replace to include the <hr /> for the Search form widget title. Any suggestions?

    I also tested with a searchform.php template and it seems that wordpress overrides any default widget code with the code in the searchform.php, so I did not end up with two <hr /> tags. I assume register_sidebar() does not apply when there is a corresponding template file for the widget. Since the searchform.php is not really necessary I removed it and will instead rely upon modifications to the functions.php file.

    Thanks again for your helpful suggestions.

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘slight modification to all widgets’ is closed to new replies.