Articles of hooks

Use a variable created in get_header to calculate stuff in wp_footer

i am trying to create a small time tester that loads at get_header hook and the using the value does something in wp_footer… i have tried using global $var i tried putting the global var inside the function i tried attaching it to the wp_head instead of get_header Here is a simplefied ver of the […]

How to alter the query using pre_get_posts hook and is_post_type_archive

The need: I’m trying to filter a custom post type archive using a GET parameter, so that I can split the posts in two groups depending on which terms they are tagged with. How: So far I’ve decided to use the pre_get_posts hook, altering the query when the archive for this custom post type is […]

Bind a function with its own argument to show something dynamically after every content

I have a function that is grabbing something from database using a user-defined ID. I need to show the content after every post/page content. So I followed @s_ha_dum’s solution from WPSE, like below: function get_my_content( $id ) { $my_content = get_post( $id ); return get_post_meta( $my_content->ID, ‘wp_c_field’, true ); } $ad_func = get_my_content(1817); echo apply_filters(‘the_content’, […]

Genesis – Adding custom hooks to display secondary navigation

within my functions.php I added the following piece of code to display my footer accordingly: //* Customize the entire footer remove_action( ‘genesis_footer’, ‘genesis_do_footer’ ); add_action( ‘genesis_footer’, ‘my_custom_footer’ ); function my_custom_footer() { ?> <div class=”site-footer-logo”> <img src=”<?=get_stylesheet_directory_uri();?>/images/my-logo-small.png” alt=”My Logo Small” /> </div> <p>Copyright &copy; <?=date(‘Y’);?>,</p> <?php } I want to have the secondary navigation menu […]

Plugin Development – Functions or Hooks?

I am brand new to WordPress plugin development and have a few questions, mostly about best practices but also some specifics. Essentially I just want to trigger an action (invoking a PHP class and calling a method) whenever the following happens: A post is published A page is published A comment is added This will […]

How to distinguish on hook profile_update user registering, user resetting password or user updating profile?

The hook profile_update gets fired in case the user updates his profile, that is also when he reset the first time his password after registration and when he register. How do I distinguish between the three cases? EDIT: There are, at least, 3 cases to distinguish, in which that hook is called. user’s first registration […]

WordPress Register Style Called Incorrectly

Why am I getting this error? Notice: wp_register_style was called incorrectly. Scripts and styles should not be registered or enqueued until the wp_enqueue_scripts, admin_enqueue_scripts, or login_enqueue_scripts hooks. Please see Debugging in WordPress for more information. (This message was added in version 3.3.) in /var/www/ on line 3792 The code I’m using to include my custom […]

Use has_filter on comment_post

I hook to comment form (on comment_form_logged_in_after if user is logged in and comment_form_before_fields if not) to add 2 fields (rating and title). These fields can be mandatory or comment will not save. These fields will not appear on comment reply or if review are not enabled for a certain post or page. If these […]

Remove word “Category” from WooCommerce product page

I’m trying to remove the word Category from the product page. As far as I know the code that displays that is woocommerce_template_single_meta located into content-single-product.php file: <?php /** * woocommerce_single_product_summary hook * * @hooked woocommerce_template_single_title – 5 * @hooked woocommerce_template_single_rating – 10 * @hooked woocommerce_template_single_price – 10 * @hooked woocommerce_template_single_excerpt – 20 * @hooked […]

Odd map_meta_cap $args on post edit — sometimes integer, sometimes string

I’ve been digging into the map_meta_cap filter since I need to extend the user’s capabilities based on context, in certain situations. This is working well but in my traces I noticed something odd about the way $args show up at the callback function. Here’s my filter registration (inside a class): add_filter( ‘map_meta_cap’, array(&$this, ‘post_map_meta_cap’), 10, […]