Is there a hook for nav menu item links to add custom css programatically?

Yes, there is, and the hook is nav_menu_link_attributes: apply_filters( ‘nav_menu_link_attributes’, array $atts, WP_Post $item, stdClass $args, int $depth ) Filters the HTML attributes applied to a menu item’s anchor element. For example, this adds the nav-link class to the <a> tag only if the theme location ($args->theme_location) is exactly my-location: add_filter( ‘nav_menu_link_attributes’, ‘my_nav_menu_link_attributes’, 10, 3 … Read more

How to catch wordpress post ID when it’s published

To put it briefly, WordPress hooks let you modify parameters or output of functions (filters) or execute custom code when something happens (actions). Both types of hooks usually pass one or more arguments to the callback functions that are attached to them. During a page request WordPress goes through series of steps to get the … Read more

sortable columns for multiple custom post types not working

I thought if I used manage_edit-post_sortable_columns I could target the ones I have conditionally checked for? That hook runs only on the “Posts” page (at wp-admin/edit.php) for managing posts in the default/core post post type. I.e. When the post_type parameter in the (current page) URL is not set or empty, or that it’s set to … Read more

Calling add_action on a filter hook?

add_action() and add_filter() are essentially the same thing, hooks, and they both call the same functions under the hood. If you look you’ll see WP_Hook::do_action() basically just calls WP_Hook::apply_filters(). An action is essentially just a filter that doesn’t return a value. If your callback function was supposed to modify the value of $role then that … Read more

Get access to variable from previous pageview, excluding ajax-calls

I found out you could identify ajax requests by the following if-statement if (defined(‘DOING_AJAX’) && DOING_AJAX) So problem solved using add_action(‘init’, ‘set_global_pixelcapival’); function set_global_pixelcapival() { if (defined(‘DOING_AJAX’) && DOING_AJAX) { } else { global $pixelcapival; $pixelcapival = pixelcapival(); global $prev_pixelcapival; $prev_pixelcapival=””; if(isset($_COOKIE[‘pixelcapival’])) { $prev_pixelcapival = $_COOKIE[‘pixelcapival’]; } setcookie(‘pixelcapival’, $pixelcapival, time() + 1200, “https://wordpress.stackexchange.com/”); } }

How to remove js ui library added by default by wordpress

The related library is registered with a function called wp_default_scripts. File location (for WordPress 6.0): …wp-includes/script-loader.php remove to remove the relevant script; The add function is used to add a new script. /** * Assigns default styles to $styles object. * * Nothing is returned, because the $styles parameter is passed by reference. * Meaning … Read more