Insert HTML in post, below nav bar but above content?

Edit your single.php or single-post.php template, depending on which one is present and in use with your theme. The JS file should be registered and conditionally enqueued when the template is loaded. This allows for dependency management and lots of other easy management actions. Another way to consider is make your menu an actual WordPress … Read more

Remove an action by extending class and replacing it

Problem lies in this line: remove_action(‘woocommerce_before_my_account’, array( $this, ‘my_packages’)); This won’t remove action registered by parent class, because $this is a different object in this case, so you won’t remove any action at all. So how to remove such action? Since you can’t access the same $this value in your class, you’ll have to iterate … Read more

How can I add text to a specific ‘Edit Page’?

To do this you would indeed have to include some code in the functions.php of your theme. You can use admin_notices to add a note to this specific page like this: add_action( ‘admin_notices’, ‘wpse332074_donotedit’ ); function wpse332074_donotedit () { $screen = get_current_screen(); if ($screen->post_type == ‘page’) { $variable = $_GET[‘post’]; if ($variable == id_of_page_as_integer) { … Read more

Hook to init or call explicitly within functions.php

If we take your code at face value, there are some consequences: it runs on every request, be that a page, an AJAX call, a REST API request, even XMLRPC It’s a super expensive post query that involves post meta, with no upper limit on the number of results You are filtering a post query … Read more

Plugin does not add action

Activation hook is run only after the plugin get activated. So only once and only during that one request. It’s meant to allow author of a plugin to perform some actions after the plugin is activated. Actions, that need to be done only once. For example if your plugin uses custom database table – you … Read more

I don’t understand how add_action and do_action work in tandem. The former executes the code already…what is do_action for?

The do_action() function executes any code that’s been hooked with add_action(). The only reason your function_save_custom_form_data() function runs is because the WP Forms plugin has added a call to do_action() inside its code. So what using do_action() in a theme or plugin does is allow other plugins or themes to run code during its processes. … Read more

Run a code only on theme activation only during first activation

What about using WordPress Options API to store a flag whether it is the first switch or not: https://codex.wordpress.org/Options_API <?php add_action(‘after_switch_theme’, ‘setup_theme_options’); function setup_theme_options () { if(get_option(‘first_theme_activation’) === false){ // Set a flag if the theme activation happened add_option(‘first_theme_activation’, true, ”, false); // stuff here only runs once, when the theme is activated for the … Read more