Is there a better way to implement responsive images than what WordPress uses by default?

Unfortunately, I’ve found the images within Gutenberg/block editor a lot left to be desired and the development work with images in 2020 has been primarily focused on adding cropping, rotating images within the block editor. The limitations of responsive images in the block editor is one of my biggest criticisms of the block editor. What … Read more

Run add_action hook if condition

I’d guess this code is being run directly from your plugin’s functions.php, meaning that you’re evaluating is_front_page() and is_archive() as you load the plugin. That’s too early – that’s before enough state has been initialised to know which page you’re on. To fix this, you either need to: move the logic into your say_hello functions, … Read more

Change WordPress RSS link with filter?

You can take advantage of the template_redirect hook and redirect any request to the WordPress feed to a URL that you define. The most important thing to consider is the case when users are attempting to access the feed itself. In that case, you’d obviously not want to do any redirection. Here’s how you can … Read more

Put code into body tags near top, using a plugin

Put that script into a file somewhere in your theme folder. Include it using the following code in your theme’s functions.php file: <?php function wpa_65602_enqueue_scripts() { wp_enqueue_script( ‘facebook’, get_bloginfo( ‘template_url’ ) . ‘/path/to/script.js’ ); } add_action( ‘wp_enqueue_scripts’, ‘wpa_65602_enqueue_scripts’ );

How can I hook into creating a new post and execute wp_die(), before the post is inserted into the database?

Try filtering with wp_insert_post_data instead. It’s from wp-includes/post.php, line 2864. add_filter( ‘wp_insert_post_data’, ‘post_publish_filter_wpse_82356’ ); function post_publish_filter_wpse_82356( $data ) { // view/manipulate $data if (‘publish’ == $data[‘post_status’]) { $msg = ‘<pre>’ . var_export($data, true) . ‘</pre>’; wp_die($msg); } return $data; } publish is the post_status when you click the Publish or Update button. The four statuses … Read more

How to check what kind of saving it is?

There are hooks specifically for this, actually. The codex has a pretty good overview. Essentially every time WordPress saves a post (which it does through wp_insert_post) or alters the status of the post, it calls wp_transition_post_status which looks like this: <?php // in wp-includes/post.php function wp_transition_post_status($new_status, $old_status, $post) { do_action(‘transition_post_status’, $new_status, $old_status, $post); do_action(“{$old_status}_to_{$new_status}”, $post); … Read more

How do I successfully create a hook for an email override?

WordPress uses the PHPMailer class for sending mail. Before calling wp_mail, you can manipulate the $phpmailer object using the phpmailer_init filter. //Place this inside of your form callback before wp_mail() add_filter(‘phpmailer_init’, ‘foobar_phpmailer’, 99999, 1); function foobar_phpmailer(&$phpmailer){ //Manipulate the phpmailer object here }

Determine plugin name from within plugin_action_links filter

There are currently four filters and they carry lots of information: $prefix = $screen->in_admin( ‘network’ ) ? ‘network_admin_’ : ”; $actions = apply_filters( $prefix . ‘plugin_action_links’, array_filter( $actions ), $plugin_file, $plugin_data, $context ); $actions = apply_filters( $prefix . “plugin_action_links_$plugin_file”, $actions, $plugin_file, $plugin_data, $context ); This is a var dump of the parameters for Advanced Custom … Read more