0

I am fairly new to wordpress but im having trouble working out how to customise the widgets.

I have customised the search widget like so (in the functions.php file)

function widget_search() {
    echo '<form role="search" method="get" class="search" action="'.home_url( '/' ).'">
    <input type="search" name="s" placeholder="Search then hit enter" />
    </form>';
}
if ( function_exists('register_sidebar_widget') )
    register_sidebar_widget(__('Search'), 'widget_search');

But i want to customise the recent posts widget and other but how to i do this. Do i just do the same method like the search on?

Iv looked at the codex but i cant seem to find the answer

0

What you have used is actually pretty obsolete remnants of "old" widget implementation.

The current implementation of widgets in WordPress is using new, class-based approach, see Widgets API in Codex.

There isn't really designated way to "customize" functionality of existing widget. Depending on circumstances you might be able to use hooks in its code. Outside of that usually widget is forked under different name or extended from existing class and registered (as a new one or replacing existing implementation).

  • ok, so basically you create a class for example "search_widget.php" and that class extends WP_Widget. But how to i call the new class instead of the old one? – user3613245 Jun 14 '14 at 17:29
  • @user3613245 I don't remember the logic of replacing one with another precisely, hadn't done that in a while. You can always simply register your as new one (and maybe unregister native one). – Rarst Jun 14 '14 at 17:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.