How to run a function when publish posts? [duplicate]

Unless you have a very specific reason, and you know what you are doing, code like this belongs in the functions.php file or a dedicated plugin. WordPress uses two kinds of hooks to allow certain functions to be triggered at specific times. These are called Actions and Filters. https://codex.wordpress.org/Plugin_API Placing code in a file that … Read more

Create 2-layered dropdown menus for custom taxonomy and custom post type

With a combination of jQuery / JavaScript and WP AJAX; you could look for an onchange event on the select box, send an ajax request to your admin-ajax.php with the year and then do a custom WP Query to return the html for the secondary drop down and append it to your dom. https://codex.wordpress.org/Plugin_API/Action_Reference/wp_ajax_%28action%29 http://api.jquery.com/jquery.ajax … Read more

How to replace native comment_count with Comments Evolved aggregate count

Few issues here. use add_filter() instead of apply_filters(), to register your custom callback. return the value within your filter’s callback. use the get_comments_number filter instead of the comments_number filter, since you only want to change the number and not the whole output of the comments_number() function. prefix the name of your custom callbacks, to avoid … Read more

Insert menu into theme location depending on user logged in/out status

Okay, figured it out! I’ve amended my theme function as follows: add_filter( ‘wp_nav_menu_items’, ‘add_loginout_link’, 10, 2 ); function add_loginout_link( $items, $args ) { if (is_user_logged_in() && $args->theme_location == ‘top_navigation’) { $items .= wp_nav_menu( array(‘menu’ => ‘menu-logged-in’, ‘container’ => ”, ‘echo’ => false, ‘items_wrap’ => ‘%3$s’) ); } elseif (!is_user_logged_in() && $args->theme_location == ‘top_navigation’) { $items … Read more

custom post type does not working when adding in child theme function

try to check you functions. That function might exist somewhere in your code. if you cant find it, then try to remove the if statement and just add your function directly like this function testimonial() { register_post_type( ‘testimonial’, array( ‘labels’ => array( ‘name’ => ‘Testimonial’, ‘singular_name’ => ‘Testimonial’, ‘add_new’ => ‘Add New’, ‘add_new_item’ => ‘Add … Read more