How can I modify the WordPress default widget output?

To expand on Mark’s answer, there’s not much (generally) available in the way of filters in the default WordPress widgets (except for perhaps widget_text). But adding your own custom widget is easy – put this in your functions.php: require_once(“my_widget.php”); add_action(“widgets_init”, “my_custom_widgets_init”); function my_custom_widgets_init(){ register_widget(“My_Custom_Widget_Class”); } Then you simply want to copy the existing categories widget … Read more

Trouble understanding apply_filters()

Try to see the function with better names: apply_filters( $filter_name, // used for add_filter( $filter_name, ‘callback’ ); $value_to_change, // the only variable whose value you can change $context_1, // context $context_2 // more context ); So when that function is called as: // wp-login.php line 94 apply_filters( ‘login_body_class’, $classes, $action ); You can use … … Read more

How do filters and hooks really work in PHP

Overview Basically the “Plugin API,” which summons Filters and Hooks, consists out of the following functions: apply_filters() – execute do_action – execute apply_filters_ref_array() – execute do_action_ref_array() – execute add_filter() – add to stack add_action() – add to stack Basic Internals Overall there’re a couple of globals (what else in WordPress world) involved: global $wp_filter, $wp_actions, … Read more

WordPress hooks/filters insert before content or after title

Just use the the_content filter, e.g.: <?php function theme_slug_filter_the_content( $content ) { $custom_content=”YOUR CONTENT GOES HERE”; $custom_content .= $content; return $custom_content; } add_filter( ‘the_content’, ‘theme_slug_filter_the_content’ ); ?> Basically, you append the post content after your custom content, then return the result. Edit As Franky @bueltge points out in his comment, the process is the same … Read more

How to remove a filter that is an anonymous object?

That’s a very good question. It goes down to the dark heart of the plugin API and best programming practices. For the following answer I created a simple plugin to illustrate the problem with easy to read code. <?php # -*- coding: utf-8 -*- /* Plugin Name: Anonymous OOP Action */ if ( ! class_exists( … Read more

tech