Remove classes from body_class

You can configure the $whitelist array in this function to filter out all other unwanted classes. add_filter( ‘body_class’, ‘wpse15850_body_class’, 10, 2 ); function wpse15850_body_class( $wp_classes, $extra_classes ) { // List of the only WP generated classes allowed $whitelist = array( ‘portfolio’, ‘home’, ‘error404’ ); // Filter the body classes $wp_classes = array_intersect( $wp_classes, $whitelist ); … Read more

Add custom options to the wplink dialog

The dialog HTML comes from WP_Editors::wp_link_dialog() but no hooks in there. We could instead use jQuery to append the custom HTML to the link dialog and try to override e.g. the wpLink.getAttrs(), because it’s very short 😉 Demo example: jQuery( document ).ready( function( $ ) { $(‘#link-options’).append( ‘<div> <label><span>Link Class</span> <select name=”wpse-link-class” id=”wpse_link_class”> <option value=”normal”>normal</option> … Read more

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

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

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

How to add defer=”defer” tag in plugin javascripts?

As of WordPress 4.1 there is a filter: script_loader_tag. You can use it to find the correct script: add_filter( ‘script_loader_tag’, function ( $tag, $handle ) { if ( ‘contact-form-7’ !== $handle ) return $tag; return str_replace( ‘ src’, ‘ defer=”defer” src’, $tag ); }, 10, 2 ); Old answer There is no dedicated filter available … Read more