How do I add something to the “Edit Tag” page in wp-admin?

There is the in_admin_footer hook that’s right before the “Thank you for creating with WordPress.” text in the footer, you can check if you’re on a tag edit screen in that hook. function wpse_277416_admin_footer() { $screen = get_current_screen(); if ( $screen->id === ‘edit-post_tag’ ) { echo ‘Hello world!’; } } add_action( ‘in_admin_footer’, ‘wpse_277416_admin_footer’ ); That’s … Read more

add_action.. will work if function is empty?

The function will run, but nothing will happen. There is a small overhead, but you shouldn’t worry about it, the possible savings are minimal. Depending on when you have $checked available, you could also do function example() { echo ‘true’; } if ($checked) add_action(‘wp_head’, ‘example’);

Send an e-mail notification to custom user role when a file is uploaded to uploads folder

You could use the wp_mail function https://developer.wordpress.org/reference/functions/wp_mail/ to send an email to anyone after the file is successfully uploaded in your directory. You do not need any action here Add it your code after the file is uploaded successfully if(empty($errors)==true){ move_uploaded_file($file_tmp,”/$user_dirname/”.$document); echo “The file was uploaded successfully!”; wp_mail(..); }else{ print_r($errors); } }

how to execute some code after a post is published in WordPress [duplicate]

You’re looking for the save_post action. This allows you to add a function when a post is saved (updated). You can hook into it like this: function your_save_post_function( $post_id ) { } add_action( ‘save_post’, ‘your_save_post_function’ ); Remember to not change WordPress Core files, as these will be overwritten when WordPress is updated. You can put … Read more

Trying to add_action in a loop

As Milo hints at in their comment, custom post types can only be registered on the init hook. Therefore, if you are trying to get all the public but not builtin post types before init, then get_post_types() will return an empty array. (You can use get_post_types() to get the builtin post types before init.) What … Read more

How to check if it’s edit.php & post_type is set?

Post type is reflected in body as class. It is .post-type-post for posts, .post-type-product for WooCommerce products and must be .post-type-food in your case. So, you can use css rule like that to detect certain post type: body.post-type-food #titlediv input { background: yellow !important; } Post status is reflected only in TinyMCE editor classes, as … Read more

Advanced WordPress plugin activation detection

The init and plugins_loaded hooks are already run before a plugin is activated. That’s why your first code doesn’t work but the second does. Regarding your third code: there’s no need to run add_action(‘myplugin_activate’ … inside init. Not everything needs to be hooked to init. Just use add_action(‘myplugin_activate’, function(){ echo ‘myplugin is not allowed.’; die; … Read more

Alter existing page contents based on url

I belive this will work for you: Create a “page” called “stuff”, then create another page called “foo”, make it child of “stuff”, now stuff/foo will exist and won’t be 404. Finally use the_content filter and make the required data manipulation. The other choice (hard way) you’d have is to use pre_get_post hook, so you … Read more