Stack Exchange Network

Stack Exchange network consists of 174 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
1answer
14 views

Is it possible to disable a theme programmatically?

I'm building a plugin that loads iframes to display some content. I have specific scripts & styles for that content and would thus like to ignore the active theme when loading those templates; ...
0
votes
0answers
6 views

Woocommerce Bookings: change price based upon user role

I'm trying to change the price for bookable products using the Woocommerce Bookings plugin. The price needs to be set to 0 if a user has a specific role. I'm using both the hook '...
0
votes
0answers
14 views

What do the args for Gutenberg subpackage “hooks” function “doAction” mean?

The package is supposed to mime WP's own actions system: https://github.com/WordPress/gutenberg/tree/master/packages/hooks I've installed it locally and loaded up all of its modules, unfortunately, ...
0
votes
1answer
25 views

WordPress v5.0.3 Gutenberg & JS error “Uncaught SyntaxError: missing ) after argument list”

After update from WP 5.0.2 to 5.0.3 I had issues in wp-admin. I couldn't edit post data. There was JS error "Uncaught SyntaxError: missing ) after argument list", undefined "_" (lodash) etc.
0
votes
0answers
16 views

Set global $wp_query/$post variable for dynamic page generation

This is a difficult one to describe, but I'll do my best... I'm trying to set up pages that can be shown based on a second (meta/ACF) slug, dependent on the language the user is using. Essentially, I ...
0
votes
1answer
16 views

How to get user profile information before update?

Currently I can send an email to admin when users update their information using the following (hooking into the S2Memeber plugin): // Email to tell us what user profile for CMM has been modified ...
0
votes
1answer
14 views

Prevent publish status/date saved on transition_post_status hook

I'm using the transition_post_status to prevent a custom post type from being published based on a post meta field. It doesn't seem to work entirely, and that's where I need some help. Here is a ...
0
votes
0answers
12 views

Unable to remove action from parent theme

I have a problem with remove action from parent theme in my child theme. Parent theme code: add_action('custom_action_name', 'function_name', 10); function function_name() { //something } Child ...
0
votes
0answers
17 views

Get order total on thank you page

I'm trying to hook into the order received text and display a message based on the total order amount. This is what I currently have, but it's not working (thankyou-page is blank after title); ...
0
votes
0answers
19 views

Modify term slug before saving

I had the same problem like in this Question. Terms like 'c', 'c++' and 'c#' are only saved once with 'c' as slug. Based on example #2 from the answer I built some code that works fine when creating a ...
2
votes
1answer
117 views

Gutenberg gallery hook errors

I try to modify the gallery block of Gutenberg and I use the following snippet export function defaultColumnsNumber( attributes ) { console.log(attributes.images.length) return Math.min( 3, ...
0
votes
2answers
27 views

Setting Cookie with init hook causes 'header already sent'

Based on research here and elsewhere, I have the following code that sets a cookie on a site: add_action( 'init', 'my_set_cookie',1 ); function my_set_cookie() { if (! $_COOKIE['mycookie']) { ...
0
votes
1answer
25 views

Hook to init or call explicitly within functions.php

Sometimes we need a function to run on every page load, so as i understand there are to options: hook it with(say init) Call directly within functions.php when it would be good to use one of them. ...
2
votes
1answer
37 views

How to get all functions with priority '1' attached to hook 'wp_head'

How to get (loop through to disable unnecessary) all functions with priority '1' attached to hook 'wp_head' ('_wp_render_title_tag', 'wp_enqueue_scripts', 'noindex' etc.)? It is necessary to get it ...
0
votes
0answers
30 views

How to use retrieve_password hook? [on hold]

I'm developing User Registration Front End function with Ajax but I don't know how to use retrieve_password in this code. I write the code based on this code. functions.php is add_action('...
1
vote
3answers
36 views

How do action and filter hooks understand where to look for the core function that we hooked our function to them

I want to know how does WordPress core files handle the relationship between module and core of the WordPress? We all know it uses add_action() and add_filter() to manipulate data according to our ...
0
votes
1answer
30 views

Can't properly set the_title add_filter to show short_URL

I am trying to show Bitly's Post short URLs for my blog posts but something seems off as when I am using this code, I see the output all over the page for menu items etc... Additionally, the URL ...
0
votes
1answer
13 views

How to access deleted term inside delete_product_cat action

I want to run some code after a product category is deleted, in that function I want to access the name of the deleted category, and according to their docs I could do this: add_action('...
1
vote
2answers
18 views

Inserting a functions output after the content

So I am trying to add a button at the end of my blog posts, here is the code I have in the plugin so far: <?php /* Plugin Name: etc.... */ function shares_content() { ?> <div class='...
0
votes
0answers
13 views

Dynamically set front page featured image from first image in latest post's ACF gallery

My front page template is set to display the full content of the latest post using WP_Query and a custom page template. Now I want the home page featured image to dynamically change every time a new ...
0
votes
0answers
26 views

Trying to run a compile command while saving post

I have a front end built with Gatsby, connecting to WordPress via the REST API. Each time I update a post, I need run a command to compile. Below is my attempt at automating this using the save_post ...
1
vote
1answer
24 views

Handling Body class based on Template

Through a PHP function, I think I can handle body class, but I think WordPress would have some specific way to handle it. If Home.php then class in the body should be wbody else it should be bgody. ...
0
votes
2answers
47 views

Remove actions/filters that are set with create_function()

This theme I was handed from another dev company is littered with add_action/filter( 'hook/filter', create_function( '', 'return blah('blah')' ); We will be moving this site to a server running php 7....
0
votes
0answers
23 views

Problem with call_user_func_array front end

This is the error im currently getting, fixed the other minor ones but this one seems to be a compatibility issue. is there any way i can change a few lines of code to fix this issue, Any help would ...
0
votes
1answer
20 views

How to output woocommerce products to a page, style and modify the html structure

I am a complete noob when it comes to woocommerce so bear with me. I have added 6 products into woo. I have a cart and a checkout page that are using shortcodes to output the php/html to those ...
1
vote
0answers
16 views

user_profile_update_errors hook not executing

I'm trying to use the user_profile_update_errors hook, however it doesn't appear to be executing. I'm calling it like this: add_action('user_profile_update_errors', 'blm_register_result', 10, 3); ...
0
votes
0answers
20 views

Custom register page and retrieving WordPress registration errors

I'm doing a custom login and register page and the login portion has gone smoothly as I can redirect errors back to my custom page because of how wordpress handles this (such as appending the issue to ...
0
votes
1answer
26 views

How can I add text to a specific 'Edit Page'?

I have a specific Page, that I do not wish to be edited. As such, I would like to place a 'Do Not Edit This Page' message within a specific 'Edit Page' file as follows: Any ideas on how this can be ...
0
votes
2answers
30 views

Issues with if, else, and elseif statements

For my site, I need to have different header colors depending on the page it's on. Here's the code I have for my site that is working: <?php if ( is_single() && is_post_type('product') || ...
0
votes
1answer
36 views

Validate custom fields before save using WordPress Rest API

I want to add custom validation to post(custom post type) before it save into the WordPress. I am using the Rest API to insert the post to custom post type. What I need is the fields which I created ...
0
votes
0answers
14 views

Add extra products on add-to-cart action

I'm having some trouble adding extra products on add to cart button is executed. Basically, the user gets a few extra products in the product to choose from, My problem is that the user can still ...
-1
votes
0answers
32 views

How to do action after successful post save/update

On the frontend, users can submit a post, and when they click a submit button, javascript uses AJAX to publish the post to the live site. However, to automatically moderate the posts, I want to run ...
1
vote
2answers
138 views

Proper way of using functions in action hook?

I am wondering if the below logic is correct and if certain circumstances should be present for it to work, since in some cases it does not seem to be working. The example below is quite simple. Let'...
0
votes
1answer
10 views

Filter default_content only for products

Is there any way to use default_content only for a certain post type, specifically product (WooCommerce)? My code: add_filter( 'default_content', 'set_default_content', 10, 2 ); function ...
-1
votes
1answer
24 views

How to filter part of a variable if it is no array?

I was wondering if it is possible to filter out a part of a variable, if it is no array. Or can I only replace the whole code, or add code to it? Let's say I have this code: $output = '<...
1
vote
1answer
87 views

hook to get (and change) the search string before processing

I'm trying to intercept the search query before it's executed in Wordpress. I've tried a bunch of things but it's just not working. So, for example, a user enters the search term RED SHOES. I want ...
-1
votes
0answers
29 views

Woocommerce checkout field autocomplete and delivery by city

I am trying to implement a customized delivery option given by the city the user has chosen. In order to do so, I started with adding a basic js autocomplete on a closed list of cities, The problem ...
-1
votes
1answer
43 views

Cannot modify header information - headers already sent

So I have a form on one page, which is submitting to admin-post.php, then there is a function in functions.php which is processing the form. It stores the input field data to database and then after ...
0
votes
2answers
21 views

Remove an action by extending class and replacing it

I'm trying to override a method (my_packages) from the WP Job Manager Paid Listings plugin by extending it's class from within a custom plugin Here is how the source code (none-related code removed) ...
0
votes
1answer
12 views

Why is pre_get_posts hook invoked multiple times?

I am using pre_get_posts hook, however as it is not working as expected, I have discovered that the function is being invoked 4 times, and while the first call is running as expected, subsequent calls ...
0
votes
0answers
21 views

Having trouble using wp_update_post

I am trying to create an action that will place the contents of a meta tag into the excerpt field, but I can't seem to get it right. The action is the publish event of a frontend submit plugin. When ...
0
votes
0answers
31 views

WooCommerce Custom Pagination Layout

as currently my site product pagination is display as PREVPAGE 1 2 3 .. 15 NEXTPAGE May I know how I can make it as FIRSTPAGE PREVPAGE 12345 NEXTPAGE LASTPAGE ? I'm trying to achieve it same as https:...
3
votes
1answer
29 views

Restrict access to admin but allow admin_post hook

I'm using this hook to allow only admin roles access dashboard add_action( 'admin_init', function() { if ( defined('DOING_AJAX') && DOING_AJAX ) { return; } if ( !...
0
votes
0answers
16 views

Woocommerce filter don't work

I noticed that some Woocommerce filter not called as needed. For example in cart view page must work filter 'woocommerce_get_item_data' but this filter not works, I wrote code in theme functions.php ...
0
votes
2answers
36 views

Custom action on login and “remember me”

I try to call a function everytime a user login to website. I succeeded with the wp_login hook for user who fill the login form. However I can't find a hook for an user which has the "remember me" ...
2
votes
1answer
47 views

Best practice custom function, where to echo the variables?

I have a custom function to query some posts. I was wondering if it is okay to echo variables within the loop of the function, since normally I would echo a variable at the end of the function. If so, ...
0
votes
0answers
24 views

Country specific pages in a site

I’m working on an multi-national site for which the sponsors want pages supported so that each page: Can be served from a single default page regardless of the country (80% of pages), and Default ...
0
votes
0answers
40 views

Need help registering a new template location into an existing Elementor action

I'm trying to find a way to register some new "template locations" within the Elementor page builder system. They have two page templates that come with the plugin, "Elementor Canvas" and "Elementor ...
0
votes
1answer
29 views

Don't prepend WordPress base url to image paths

I'm programmatically adding image attachments to posts, however I'm not uploading the image, just storing the full url which is hosted on a CDN e.g. https://i.atcdn.co.uk/imgser-uk/imgser-uk/servlet/...
0
votes
2answers
23 views

Transform .wp-video to the native video player of the browser

Is there a way to display a video using only the default video player of the browser, without the mejs / wp-video interface? The additional markup gives me a lot of trouble. I just want to use the <...