enqueue script/style plungin development

You’ve given wp_enqueue_style a directory, but no file name. Have a look at https://developer.wordpress.org/reference/functions/wp_enqueue_style/: The first parameter of wp_enqueue_style is the name, or handle, of the stylesheet as referred to internally by WordPress (this should be a unique name for each stylesheet you enqueue) The second parameter is the src to the stylesheet – so … Read more

Internationalizing Plugin

You have to load text domain in your plugin: <?php function my_load_textdomain() { load_plugin_textdomain( ‘add-to-post-footer’, // text domain identifier false, // deprecated parameter plugin_basename(dirname( __FILE__ )) . ‘/languages’ ); // path to the languages directory } add_action(‘plugins_loaded’, ‘my_load_textdomain’);

Creating an empty page programatically

Add a post meta field to indicate this post is just a redirect when creating it: $postid = wp_insert_post($newpost); add_post_meta($postid,’redirect’,’1′); Check the post meta value and if it is a “redirect post”, just output the post content (javascript redirect): add_action(‘wp’,’custom_maybe_redirect’); function custom_maybe_redirect(); global $post; if (!is_object($post)) {return;} $redirect = get_post_meta($post->ID,’redirect’,true); if ($redirect == ‘1’) {echo … Read more

After plugin activation hook

In the context of official plugin repository this is very explicitly forbidden by the guidelines (emphasis mine): 7. No “phoning home” without user’s informed consent. This seemingly simple rule actually covers several different aspects: No unauthorized collection of user data. For example, sending the admin’s email address back to your own servers without permission of … Read more

Customize existing menu item

Given that you want to include a picture in the wp_nav_menu output, your best bet is to use the wp_nav_menu_items filter, as suggested in the comments. This will allow you to do a search and replace on the html. add_filter (‘wp_nav_menu_items’,’wpse229358_filter_menu’); function wpse229358_filter_menu ($items,$args) { $search=””; // html string of button $replace=””; // html string … Read more

Autogenerate a Table of Contents

Sure. In your single.php or where you loop through the posts, start by getting the content: $content = get_the_content(); Then use a regex where you target anything within <h2> tags: $regex = ‘/<h2>(.*?)\<\/h2>/u’; And then use preg_match_all() to find all titles: preg_match_all($regex, $content, $table_of_content); This will create a multidimensional array, see: print_r($table_of_content); So you have … Read more