How to reduce original image quality on upload?

In general I wouldn’t recommend modifying the original uploaded image files, just in case we might need to re-generate intermediate sizes. But let’s see if it’s possible 🙂 We can in general let WordPress choose the image editor, that depends on modules like GD or Imagick, through: $editor = wp_get_image_editor( $file ); but this can … Read more

Can we completely remove the WordPress Sitemaps (WordPress 5.5)?

Disabling the sitemap is easy, just add this line to your functions.php: add_filter( ‘wp_sitemaps_enabled’, ‘__return_false’ ); Removing specific posts goes like this: add_filter( ‘wp_sitemaps_posts_query_args’, function( $args, $post_type ) { if ( ‘post’ !== $post_type ) { return $args; } $args[‘post__not_in’] = isset( $args[‘post__not_in’] ) ? $args[‘post__not_in’] : array(); $args[‘post__not_in’][] = 123; // 123 is the … Read more

Add new “Insert Into Post” button with another function

There’s a get_image_send_to_editor() function in wp-admin/includes/media.php that runs this: apply_filters( ‘image_send_to_editor’, $html, $id, $caption, $title, $align, $url, $size, $alt );. Try hooking that filter. Edit: Help with the filter call… Your call to hook the callback would look like this: add_filter(‘image_send_to_editor’, array(&$MyClassReference, ‘filter_iste’), 10, 8); The 10 is the priority, you might need to adjust … Read more

How can I remove the title “leave a reply” in the comment box in twentyeleven?

You can filter the default comment_form arguments (which is what’s causing the “leave a reply”). Just drop this in functions.php or in a plugin file. It would probably be better to put it in a plugin and keep your twenty eleven theme unedited (read: easily updated). <?php add_filter( ‘comment_form_defaults’, ‘wpse33039_form_defaults’ ); function wpse33039_form_defaults( $defaults ) … Read more

Apply jquery script to only woocommerce product pages and categories

There are two ways you could do that. 1. Using JS only WordPress themes normally use the body_class() function. As a result you’ll see that the <body> tag will have lots of classes. You can then target pages with a specific class to run your code in JavaScript: if( $(‘body.whateverclass’).length || $(‘body.anotherclass’).length ){ // Your … Read more

How to call WordPress functions from a form processing script

You should never post anything to plugins files directly. It’s almost always a security flaw and it prevents site owner from hardening the site properly (in perfect situation no requests to PHP files inside wp-content should be necessary at all) Good practice is that you use admin_post actions… (similar to admin_ajax). So your form should … Read more