Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

Questions tagged [hooks]

Method by which plugins and themes extend core WordPress functionality.

0
votes
0answers
14 views

Hook before content of list page

I have added a code to show banner on top of category page add_action( 'woocommerce_before_main_content', array( $this, 'wcb_show_category_banner'), 30 ); By this code, I am getting banner top of ...
0
votes
1answer
22 views

Assigning alternate single-{cpt} template based on blog_id in multisite

I have a multisite network with some shared custom post types, and I'm trying to create a function that loads a custom single-{cpt} template for a given post type by $blog_id when defined, and ...
0
votes
1answer
24 views

How to perform action when plugin/theme editor is used?

I'm attempting to log lots of WP activities to create an audit trail. I'd like to disable the plugin and theme editors entirely, but it is not an option. Those functions appear to be very light on ...
1
vote
1answer
41 views

Conditional action hooks

Im developing an plugin that uses AJAX, but im having trouble controling the codeflow. I want to hook functions after running conditionals. My hooks wont fire when adding them inside a control ...
1
vote
1answer
8 views

Highlight “Show all” item in wp_list_categories

I use wp_list_categories to display category filters on post archives. I can use current_category param to set current category - and such item will get addition class current-cat. I can even omit ...
0
votes
2answers
26 views

How to run a function after wp() in the wp-blog-header.php file?

I want to run a function after the wp(); line in the file wp-blog-header.php, what is the proper hook to use here? <?php /** * Loads the WordPress environment and template. * * @package ...
0
votes
0answers
9 views

How to get post categories before publish/update post?

Im trying to get the post category before it be published, it is possible? Because I need to check some things before publish at all. public function __construct() { add_filter( '...
0
votes
2answers
15 views

How to call a function or method that is Namespaced using another plugin

I'm using an action from one plugin that needs to call a function from another plugin. That function is name spaced. Typically, I would use something like: add_action( 'hook_name', 'function_name' );...
0
votes
0answers
28 views

Is there a way to disable ajax add to cart for specific products on single product pages

I would like to disable ajax add to cart for specific products, products that have add on's enabled by the Woocommerce product add on plugin as ajax add to cart is not compatible with products using ...
0
votes
1answer
14 views

WooCommerce checkout page price break down table hook

I want to add a new price break down line to the WooCommerce breakdown page. I've looked at using these hooks which supposedly should allow me to post to the table. ...
-1
votes
1answer
18 views

Auto append text after the title?

Original Title -> Original Title - Lorem ipsum How can I do this with hard code? I want this to stop people that web scrape my web without giving credit and making money off my posts from their ads ...
0
votes
1answer
22 views

Remove lines from RSS Feed

I'm trying to remove the "The post xxx appeared first on xxx" line in my RSS feed using the the_content_feed hook. I've tested the regex function outside wordpress on the feed and it works. I'm ...
0
votes
1answer
27 views

providing access to post_id or post inside functions.php

I'm trying to add metaboxes to the bottom of any post which is created from a specific post template. ie I don't want metaboxes on all my posts, just certain posts. At the point when I decided to ...
0
votes
1answer
21 views

wordpress hooks

I am currently using a woocommerce theme, Hotel (https://woocommerce.com/products/hotel/). I just recently created a home page and a blog page the way way it is explained in this site: https://www....
0
votes
0answers
16 views

WordPress Plugin Boilerplate - add actions and/or filters based on user's role

I am developing a plugin using WordPress Plugin Boilerplate. Some of its functionality need to be available only when a shortcode gets resolved in a page and furthermore some of it only if a user is ...
0
votes
1answer
23 views

use apply_filters return taxonomies custom post type

I reused the following code where a specific taxonomy is registered: public static function get_taxonomies_to_register() { $taxonomies = apply_filters( 'wp_taxonomies', array( 'wp_course'...
1
vote
1answer
13 views

Change username before login

How to change username before submitting in login form ? I have used mobile number as username when a user registers in site. also I have removed 0 from the beginning of the mobile number. Now in ...
0
votes
1answer
16 views

Cookie cant be read even cookie is present

add_action( 'wp', 'setCookies', 10); I am using this hook to set cookies. I am using 'wp' because I need to get the current post ID. Now on my sidebar.php, I am calling if(isset($_COOKIE['...
0
votes
0answers
46 views

Filter parent_file doesn't working

I am trying to highlight an admin menu option (top level or submenu) but it just doesn't work. The code should be pretty straight forward but it seems that my filter isn't triggered. add_filter('...
2
votes
1answer
27 views

WP showing “warning: call_user_func_array()”, What to do?

I am currently working on designing my blog and am almost done but when I updated to 5.1 WordPress version in XAMPP, it started showing up this error message: Warning: call_user_func_array() expects ...
0
votes
1answer
14 views

Check when a setting has been changed

New to WordPress plugin development and I am looking for a hook that will execute when a setting has been changed in the 'Admin Dashboard' > 'Settings pages'.
1
vote
0answers
9 views

How to add custom classes to figure element only if image has caption?

I want to add the 'wp-caption' class to the figure element only if the image has caption. How do I do that? I'm using the new gutenberg enviroment, if that affects anything. for example: form this: ...
1
vote
1answer
25 views

Remove a div from RSS feed

If someone can help to remove a div from my RSS feed. I want to remove below code from my RSS feed. <div class="well"> <a class="btn" href="foo.com">foo</a></div> Thanks in ...
0
votes
0answers
40 views

wp_get_current_user Not working

I am using the wp_get_current_user() function inside a hook which fires before email is sent from contactform7 . The function works but the main problem is that the function doesnt return the current ...
0
votes
0answers
16 views

Hook into WooCommerce Update Account

I've added a custom tab to my WooCommerce 'My Account' and need to fire another function when the options are saved. How can I hook into that update process? I found add_action( '...
0
votes
0answers
16 views

woocommerce_order_status_completed hook does not run

I need to add a new role to my recently registered user (upon buying any of my four specific subscriptions products). Until now, every recently registered user (those who buy a subscription product) ...
0
votes
0answers
10 views

Contact form 7 / return a result in AJAX

I have a classical contact form with some values and I want to do some maths :) like this : add_action('wpcf7_before_send_mail', function ($contact_form) { $title = $contact_form->title; $...
0
votes
0answers
18 views

Is it possible to intercept all ajax requests and get the parameters and the returns?

Is there any hook that always goes through it, where I can see all the requests, and also the returns after the "action" that is executed? I need to intercept all requests, including requests from ...
0
votes
1answer
36 views

How can I output all apply_filters and do_action?

I would like to output all apply_filters and do_action to give the user an overview of them. If I use the Code add_filter( 'wpErpOs_testFilter', 'wpErpOs_testFilter_callback', 10, 1 ); function ...
0
votes
0answers
29 views

Hiding Woocommerce categories from a menu if empty

I want to hide empty categories in a specific menu I found this code, but it hides some of my pages too. Can I some how restrict it to only hide in a specific menu? function ...
0
votes
0answers
26 views

change author of a woocommerce product [closed]

I'm trying to change the ID of 'post_author' of 'shop_order' post type in wordpress-woocommerce. So here is what I'm trying to do: When a customer is buying a product with the product Id of 356, I ...
0
votes
1answer
31 views

How to elect position of new item output in a dropdown when using add_filter

Hello I am using the suggested snippet here to add a new term to a dropdown menu: https://wpjobmanager.com/document/applications-customising-application-statuses/ which is: add_filter( '...
2
votes
2answers
167 views

How to replace any occurence of Gravatars with a local placeholder image?

Users can upload an avatar as a local image file on my website. If they didn't do so, it will fall back to the WordPress default (Gravatar). But I want any occurrence of Gravatar to be replaced with a ...
0
votes
0answers
19 views

personal_options_update hook not updating data if it contains “&”

On 'Edit Profile' page I'm trying to update user selected custom taxonomy and it works just fine but it's not updating any taxonomy which name contains "&" symbol. For example I have taxonomy ...
0
votes
1answer
21 views

Plugin does not add action

I am new in Wordpress plugin development, and I wanted to create simple plugin, which will add 2 fields into General settings in Wordpress administration. I got following code (which works fine), from ...
0
votes
1answer
17 views

How to use a 3rd party library to send emails?

I'm trying to improve my emails deliverability by sending emails that are correctly authenticated (correct SPF and DKIM configuration). I have done the SPF part, but in order to use the DKIM i need to ...
0
votes
1answer
13 views

Hook to display element as product on category page

I am creating a plugin and I am trying to add an element which will be displayed as a product. In the picture, the element is the red rectangle. I have used this guide but none of the hooks there ...
0
votes
2answers
45 views

Re-order search results with posts_orderby filter and post meta value

I'd like to re-order the search results based on post meta and date . The post meta key is _prioritize_s and the value isn't important. So in a "normal" meta query, I'd just write the compare ...
1
vote
1answer
36 views

Delay an action until current action is completed

I have two actions that run when a post is updated. The issue is, the second function runs before the first has completed. add_action('save_post', 'postUpdate', 10); add_action('post_updated', ‘...
0
votes
0answers
24 views

deleted_$taxonomy not getting fired

Want to call a function after my custom taxonomy was deleted. But the hook is not getting fired. Registered taxonomy on init hook callback register_taxonomy( 'college-session', '...
0
votes
1answer
16 views

How to change how long items are kept in the trash?

When the trash feature is enabled, the deleted posts are moved to trash and stored there for 30 days. And there is a schedule/wp_cron event that is responsible for removing these posts permanently ...
3
votes
0answers
30 views

Hooking a callback into the code within a Gutenberg block

I want to run some JavaScript when a user uploads an image or images using the core/image block or core/gallery block. Ideally I would run my own code when the onSelectImage function is called (and ...
0
votes
1answer
24 views

How to change posts order on Category and Tag archives?

WordPress by default order posts in descending order by date. But I want them to be in ascending order by date. How do I turn the order to ascending only for tags and category? I don't want blog post ...
0
votes
1answer
21 views

Security question - Display a General Custom Login Error Message

I need to change the information given on Wordpress' Login page and the Lost password page so that hackers cannot easily see if a username or email is associated with an existing account. At the ...
1
vote
1answer
60 views

How to call function at the bottom of post using plugin?

I am creating a plugin and need to write a function which will invoke at the bottom of posts. Currently, I have a shortcode created and I'm calling the shortcode at bottom of each post wherever ...
0
votes
0answers
40 views

Replace category titles inside RSS feed

I need to replace titles in <category> ... </ category> tag inside the default RSS feed (mywebsite.com/feed/). Of course, it would be more convenient to just rename the categories, but ...
0
votes
1answer
20 views

Check if `do_action()` in WordPress returns any result

I want to check if do_action('some_hook') in WordPress returns/echoes any result for a specific post. I've tried using has_action('some_hook') but it only checks if 'some_hook' has any registered ...
4
votes
1answer
119 views

Set default image link target in Gutenberg image block

I want to set the default target of the image block in Gutenberg to "Media File": I've found solutions for the classic editor, and one that appears to work for Gutenberg galleries by editing the ...
1
vote
1answer
14 views

Where (or when) should I register a new taxonomy?

I'm writing a plugin and my question is: Which is the most suitable point in which to place the code to register a custom_post_type, or a taxonomy: "init action", or "activation_hook" ??? 1)...
0
votes
1answer
21 views

Is there a hook that triggers when grant secondary user role in Wordpress?

I know when change primary role, set_user_role will be triggered, is there a similar hook for grant secondary roles?