The function called on the wp head hook becomes null

As an alternative you could try declaring it with $GLOBALS[‘a3’] in file2 to make sure it becomes a global: $GLOBALS[‘a3′] = Sample_Class::instance(); I’d guess the current $a3 declaration in file2’s top level scope doesn’t count as global because it gets inluded inside the test_loaded() scope. From the ‘include’ docs (which cover require and require_once too): … Read more

Redirect to a page while maintaining search query parameters without causing an infinite loop

I achieved this with a couple filters: add_filter( ‘query_vars’, ‘addnew_query_vars’, 10, 1 ); function addnew_query_vars($vars) { $vars[] = ‘r’; // var1 is the name of variable you want to add return $vars; } function redir_cat_match($a) { global $wp_query; if ($wp_query->is_main_query() && $wp_query->is_search()){ if ($wp_query->query_vars[‘s’] != “”){ if ($_GET[‘r’] != ‘0’){ if (!empty($wp_query->posts[0])){ $s_value = $wp_query->query_vars[‘s’]; … Read more

Getting the same post on my related post

‘post_not_in’ => array($post_id), Here is your problem, and there are two of them: The parameter key is misspelt There’s a massive performance hit that can be easily avoided Using the Correct Key It should be post__not_in not post_not_in. This will restore the desired behaviour, but with a huge performance hit that gets heavier as the … Read more

Why does my custom plugin only function correctly once per page?

The reason your code only applies to the first table, is because you are only selecting the first input with var number = document.querySelector(‘.nutrition-table__number’); You need to loop over all your tables, and add an event listener to each. Here is an example of how this could work. The plugin pattern is from https://vanillajstoolkit.com/boilerplates/revealing-module-pattern/ /*! … Read more

Changing the pointing of assets from old server to new server

Usually scripts and styles are loaded with wp_enqueue_script or wp_enqueue_style in the theme’s functions.php. That’s the most common scenario. This function takes an $src parameter which is the absolute URL to the resource, and the best practice is to use get_stylesheet_directory_uri to retrieve the URL to the folder containing the script. This way, if the … Read more