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

How would one modify the filtering Gutenberg applies to pasted content?

In my blocks.js , located in wp-includes/js/dist/ I find the RemoveInvalidHTML function, which seems to responsible for removing styles from pasted HTML. /** * Given a schema, unwraps or removes nodes, attributes and classes on HTML. * * @param {string} HTML The HTML to clean up. * @param {Object} schema Schema for the HTML. * … Read more

What is the very earliest action hook you can call?

muplugins_loaded is the earliest hook. Depending on your wordpress setup, you may not have any plugins in the MU_PLUGINS directory. In that case this hook may not fire. The next best hook to trigger is plugins_loaded. RESOURCES WordPress Codex – Action Reference List Q/A: How to get WordPress’ hook run sequence? Q/A: Make sense of … Read more

Dynamically exclude menu items from wp_nav_menu

Method 1 You can add a constructor to your custom Walker to store some additional exclusion arguments, like: class custom_nav_walker extends Walker_Nav_Menu { function __construct( $exclude = null ) { $this->exclude = $exclude; } function skip( $item ) { return in_array($item->ID, (array)$this->exclude); // or return in_array($item->title, (array)$this->exclude); // etc. } // …inside start_el, end_el if … 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

single-{$post_type}-{slug}.php for custom post types

A) The Base in Core As you can see in the Codex Template Hierarchy explanation, single-{$post_type}.php is already supported. B) Extending the core Hierarchy Now there’re gladly some filters and hooks inside /wp-includes/template-loader.php. do_action(‘template_redirect’); apply_filters( ‘template_include’, $template ) AND: a specific filter inside get_query_template( $type, … ) named: “$type}_template” B.1) How it works Inside the … 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

apply_filters(‘the_content’, $content) vs do_shortcode($content)

QUESTION AND ANSWER REVISITED There are sometimes these questions that nags you and hunts you down later in life again, and this is one such question. This question had me thinking about an alternative solution to the problem. As I already stated, custom fields and meta boxes are there to store small pieces of meta … Read more