Hot answers tagged

7

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> <...


7

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(){ ...


4

You do not need to create a complete new widget to do what you need to do. As I read your question, you are just interested in changing how the categories are displayed on the front end. There are two functions that displays the categories on the front end wp_list_categories() which displays the categories in a list wp_dropdown_categories() which displays ...


4

You can override the default WordPress widgets by extending them. The code for the default Categories widget can be found on the following link: https://developer.wordpress.org/reference/classes/wp_widget_categories/widget/ and below is an example code how you can override the output of the widget. Class My_Categories_Widget extends WP_Widget_Categories { ...


4

There are e.g. the following dynamic sanitize_term_fields() filters: edit_term_{$field} filter for the edit context pre_term_{$field} filter for the the db context term_{$field}_rss filter for the the rss context term_{$field} filter (default) and also the taxonomy-specific ones: edit_{$taxonomy}_{$field} filter for the edit context pre_{$taxonomy}_{$...


4

Your analogy here is partially correct, but incomplete: I understand that when do_action is called wp looks for all registered listeners and invokes them according set priority. You need to consider what happens when you call add_action. WordPress never searches for the add_action statements, it has those in a list. When you call add_action, it ...


4

One of the easier ways to do this is to just add the filter before your query and remove it after: add_filter( 'posts_orderby', 'filter_function' ); $something = new WP_Query( $args ); remove_filter( 'posts_orderby', 'filter_function' ); Then you can just add your function into functions.php as normal: /** * The below function filters something * ...


4

I wonder if you could override the [rev_slider] with this kind of wrapper: add_shortcode( 'rev_slider', function( $atts = array(), $content = '' ) { $html = ''; // Your custom banner HTML $banner = '<div id="bannerHTML"><!-- banner HTML goes here --></div>'; // Append your banner HTML to the revslider's output if( ...


3

Why to edit the whole form ? Filters are good because they gives you the current output and you just need to add your string to it then return it back to WordPress. In above example you are not using it so let use it. Example:- add_filter('the_password_form', function( $form ){ $my_html = '<h2><br>Password Protected Area</h2>'; ...


3

My preference is a special query var that acts as a flag to trigger your filter: function wpse_228386_maybe_batman( $clauses, $wp_query ) { if ( $wp_query->get( 'iamthebatman' ) ) { // Fight crime } return $clauses; } add_filter( 'posts_clauses', 'wpse_228386_maybe_batman', 10, 2 ); Now you can "activate" it anywhere you like, ...


2

You need the !is_admin() check. This will return false on admin pages, failing your condition. On front end pages, that condition will return true, executing your conditional statement if ( !is_admin() ) { // Do something only on frontend }


2

This is a solution I've come up with after refining it a bit. The below should only run if the shortcode exists in the content. It loops through all the shortcodes to find the specific one we need, replaces it with the shortcode plus the new HTML: function insert_after_shortcode( $content ) { if( ! has_shortcode( $content, 'shortcode_name' ) ) { ...


2

Looking at the core, there's no trace of any filter or action in the wp_link_dialog function, which would have made your life easier... Investigating how others has solved this problem, there's a plugin that does more or less the same as you want. Basically it deregisters the wplink.js, wp_deregister_script('wplink'); and registers again a modified version ...


2

The action name suggests it is run _after_the_content, not within the the_content itself, so you might have to do something different here like @SamuelElh is suggesting... You would add a function to the action with early priority to buffer, then add a filter to the final output with a late priority: add_action('tribe_events_single_event_after_the_content',...


2

The dynamic filter "term_{$field}" is probably what you're looking for, where the field is "name." One approach is to have an array of names and their pseudonyms, then do a check-and-return on them so they'll display the replacement. add_filter( 'term_name', function( $value ) { $terms = [ 'old' => 'new', ]; // basic example check, ...


1

Off the top of my head - put this in your functions.php: add_filter( 'infinite_transporter_in_same_cat', '__return_false' );


1

image_make_intermediate_size was not the hook I was looking for, but intermediate_image_sizes_advanced. Here is a working code: function disable_upload_sizes( $sizes, $metadata ) { // Get filetype data. $filetype = wp_check_filetype($metadata['file']); // Check if is gif. if($filetype['type'] == 'image/gif') { // Unset sizes if ...


1

currently there is no good tool for resizing animated gifs Resizing of animated gifs is supported by ImageMagick, which happens to be the default image library of WordPress. The only thing is WP doesn't support this filter in its default API to ImageMagick. Fortunately, it is possible to intercept image_make_intermediate_size, the hook that produces the ...


1

I found an exact solution I'm looking for. function my_comment_link_filter( $link ) { $link = str_replace( get_permalink() , $custom_permalink , $link ); return $link; }; add_filter( 'get_comment_link', 'my_comment_link_filter' ); It does exactly what I am looking for: It replaces the Page Permalink with the dynamic permalinks when I call the ...


1

The top answer (from 4 years ago) no longer works, but the WordPress codex has the solution here: <?php function add_posttype_slug_template( $single_template ) { $object = get_queried_object(); $single_postType_postName_template = locate_template("single-{$object->post_type}-{$object->post_name}.php"); if( file_exists( $...



Only top voted, non community-wiki answers of a minimum length are eligible