Questions tagged [hooks]

Method by which plugins and themes extend core WordPress functionality.

Filter by
Sorted by
Tagged with
0
votes
0answers
16 views

Hook add_attachment error

I am trying to optimize my images when uploading to website. I trying to write plugin, that will use hook 'add_attachment' and after attachment uploaded do image converting. add_action( '...
0
votes
1answer
26 views

WordPress redirect redirecting too many times or not at all

I am new to WordPress. I am trying to simply redirect users to a login page if they go to the account page without being logged in. I first tried adding this code to the functions.php code: add_action(...
0
votes
0answers
10 views

Print additional fields in wp_new_user_notification_email_admin

I have added a new field in user registration form of a Wordpress website using below code: add_action( 'woocommerce_register_form_start', 'twooc_extra_register_fields' ); function ...
0
votes
0answers
21 views

How to make WordPress search page use a relative path

I am working with a WP blog hosted on a subdomain (eg. wp.foo.com). The primary domain (eg. foo.com) is a non-WP platform running a main app/service. For blog content, however, the main platform uses ...
0
votes
0answers
48 views

Insert <canvas> with wp_footer hook [closed]

Using wp_footer hook to add a <canva> element to the page is printing <canvas class="my_canvas"> instead of <canvas class="my_canvas"></canvas> Here is the ...
0
votes
1answer
27 views

Action / Hook when a new plugin is added

Is there an action hook when a new plugin is installed? I want to hook into the moment when a new plugin was put into the /wp-content/plugins folder. So really just adding the plugin (either via ...
0
votes
1answer
23 views

Pass debug_backtrace() in Wordpress filter

As you know, debug_backtrace() function has a large output. I need to pass it in my filter. $meta = apply_filters( 'filtername' , $meta , debug_backtrace() ); Does this have a big impact on site ...
0
votes
1answer
23 views

wp_logout hook never triggered

Long story short. In wp-config.php: define('WP_DEBUG', true); define('WP_DEBUG_DISPLAY', false); define('WP_DEBUG_LOG', true); In the main file of my plugin, in the constructor: public function ...
0
votes
1answer
14 views

"Intercept" enqueing of 3rd party's JS file

I'm using a 3rd-party plugin, but I need to load the non-minified version of a specific JS file of the plugin, to avoid some image preloading caching; in the AJAX call when preloading some images, the ...
1
vote
1answer
21 views

How to correctly detect accessing wp-content/uploads?

Not sure if this is a stupid question or not; however, I've been trying to detect when a user accesses a PDF. I want to be able to know how often a user is accessing specific PDF files. I have been ...
1
vote
0answers
61 views

Remove_action does not work

I am using Shopwise theme. In the category pages, the woocommerce shop loop is being used. The template for each product in the list view is retrieved from content-product.php. Here's what I added in ...
0
votes
2answers
34 views

Can we change the hook firing sequence?

In admin, I need to fire the save_post action before firing the transition_post_status hook. But according to this, the transition_post_status fires first before the post is saved. How can I reverse ...
0
votes
2answers
31 views

changing genesis_before_while in new theme framework

I am moving a site from a Genesis theme to Colorlib theme. The genesis theme includes add_action( 'genesis_before_while', 'custom function' ); in a custom archive page, which loads restricted content ...
2
votes
1answer
157 views

Define a function outside a class and call the function using action or filter hook

Hi Currently i am developing a sub plugin for my own main plugin. Please see the main plugin code below <?php class MyClass { function __construct() { function test1() { ...
0
votes
0answers
23 views

apply_filters() and call_user_func() to define and call a function outside a class

Hi Please see the following code of my class class MyClass { function __construct() { $this->autoload_function(); } function autoload_function(){ $my_array=...
0
votes
0answers
16 views

Replace a single variable with add_filter

I'm trying to hook to a function in class-wp-query.php and replace a single variable – $searchand = ' AND ' into $searchand = ' OR '. The trouble, I assume, is that it's only the third occurence of ...
0
votes
0answers
18 views

Use ID as slug for product category by default in WooCommerce?

We have a non-English store with WooCommerce. Product categories are created with the same slug as the title of non-English characters making the URL not so pretty nor shareable. How can I make ...
0
votes
1answer
24 views

Why does wp_head hook my functions to the beginning of my source code?

Why does wp_head hook my functions to the beginning of my source code, despite the fact that 'wp_head' appears in my code just before the tag. Below is the source code <php? function load_css()...
0
votes
1answer
26 views

add short description under price

Trying to build a website but seems by default it does not show the short descriptions on page. I want to put short description below price. Tried many things but noting works really well, Just wish ...
0
votes
1answer
26 views

How to dynamically parse and transform post/page content before displaying it?

I have several posts where part of the displayed content will depend on several conditions. I am thinking on creating a custom html tag. Then, before displaying the post content, the conditions will ...
0
votes
1answer
30 views

How to load another post if condition is true

if a condition is true I want to display another post selected by its id on single.php. I have this, that gives me the current id. But how can I load the content (title and acf-fields) of another post....
0
votes
1answer
20 views

How to use template_include hook with form submission?

I'm writing a plugin that uses the template_include hook to use a custom template for a custom post type. This works with GET requests, but with POST requests, it 404s because the $post variable is ...
0
votes
0answers
20 views

Adding Plugin Assets to Header

I am creating a WordPress Plugin. I have already added some pages. But I want to add custom CSS to that pages in the <head>. I am trying: add_action( 'wp_head', 'DisHeaderAssets'); But nothing ...
0
votes
1answer
22 views

Inject div from plugin into DOM, no matter what theme is installed

I write a small cookie consent plugin for a Multisite network installation. So, when the plugin will be finished, it will be available to all instances of a multisite installation. To make it work, I ...
0
votes
0answers
14 views

Filter widget_posts_args not working

I am trying to use a filter for Recent Posts in a plugin, but it seems not works. I am using inside a plugin: add_filter('widget_posts_args', 'transk_widget_posts_args'); function ...
0
votes
0answers
20 views

Rewrite the search page to use an appended slug + parameter

I have two URLs that handle search ~/search/ = main search page ~/?s= = results page What I want: to have one search page where the search parameter for the results page appends to the search page ...
0
votes
0answers
18 views

Moving Javascript from footer to header

Plugin class is using action-hook for wp_footer in it's init function to assing script to footer. In that callable it does do two things: Registers the script (with in_footer argument true) Enqueues ...
0
votes
1answer
19 views

Getting Post ID at "stylesheet" and "template" hooks

I'm trying to create a plugin where you can select a different theme on every page. To get the selected theme I need to get the post id inside the "stylesheet" and "template" hooks ...
0
votes
0answers
27 views

Filter wordpress posts without searching the keywords in the post content

We've a courses website where we want to filter posts/courses by the keywords present in the category and/or title. Currently when filtering, the keyword is also being searched in the post content ...
0
votes
0answers
14 views

Session management issues with WordPRess 404 Error page

I have tried to integrate wordpress into my existing website as the documentation archive using the existing login session. I have installed wordpress under /wp of the root app. In my main app, I set ...
0
votes
1answer
26 views

Call to undefined function is_home() or any conditional tags

Currently I am coding in my own custom plugin. For some reason I can't use conditional tags inside my function. For example function check_home() { if(is_home()) { $my_val=1; } else { ...
0
votes
0answers
27 views

woocommerce_package_rates not fired everytime

I am using woocommerce_package_rates hook on woocommerce so I could change the flat rate on checkout page, but the problem is when someone access the checkout page its not triggering everytime. This ...
0
votes
1answer
10 views

Associate multiple email addresses with the same user account, so they can log in with either

Is there a way to associate multiple email addresses (2) with the same user account? The goal is for the user to be able to use their company email or personal email to log into a company portal - ...
0
votes
0answers
18 views

Template_redirect works, but headers aren't sent when checking via cURL

I'm creating a 307 redirect to maintenance page for when my site goes through maintenance. My PHP class is included in functions.php, and gets instantiated immediately. In my __construct, I call: ...
0
votes
0answers
24 views

Using Remove Action Hook in Plugin

I'm trying to remove a hook using the remove action hook in a plugin I'm working on. However, the code I wrote in the function.php file (child theme) does not work. If I directly comment the hook (...
0
votes
0answers
36 views

Using `set_transient()` when saving a custom post type

I've got multiple custom post types registered via a plugin and one of them is used as a precursor for multiple other queries. In an attempt to reduce queries throughout the site, I've attempted to ...
0
votes
1answer
26 views

Query String Link With Anchor Tag Not Working on Same Page

I have created a store/franchise locator page here. Once users click "Contact Franchise" on the locator, the franchise name is passed to the form underneath. The query string looks like this ...
0
votes
1answer
25 views

Add item to the woocommerce dashboard menu from a plugin

I was wondering if there's a way to add a menu item to access my plugin settings on the Woocommerce menu dashboard. I've tried using the admin_menu hook, but no success at all. Thank you everyone!
1
vote
1answer
20 views

best practice for query string values - get_query_var always empty for my value supplied in query string

I'm constructing a form in my WP plugin. I need to specify which records to modify by supplying a value in the URL like so: https://example.com/wp-admin/admin.php?page=my_plugin-event-video-assoc&...
0
votes
0answers
15 views

Variation prices breakdown only for single product page

Hey I'm trying to display breakdown of selected variation price but only on product single page. I dont want to overwite the price but just to show it after the add-to-cat and buy now buttons.For ex ...
0
votes
0answers
22 views

Adding a new hidden field based on a condition in Ninja Forms

I am rendering Ninja Forms dynamically. By dynamically I mean the shortcode is coming from an ACF field, so at different pages, there would be different forms or multiple different/same forms on the ...
0
votes
0answers
73 views

Removing "There is no account with that username or email address." error message in "/wp-login.php?action=lostpassword"

Would like to find out if there is any way I could customize the wp_login page to remove the "There is no account with that username or email address." validation (show below) and any email/...
0
votes
1answer
60 views

template_redirect hooks redirect wrong URL

I made custom plugin about login, register, and forgot password. And I give my plugin add_action template_redirect hooks to verify email, when user login and then redirect to homepage, and forgot ...
0
votes
1answer
57 views

Wordpress Custom Hook with Class method

The code described below works normally outside of wordpress, but in wordpress I get "warning expects parameter 1 to be valid callback function mycars ($ mycarsclass) not found". If I remove ...
0
votes
1answer
27 views

How do I use pre_option_{option_name} correctly?

I am using a filter to decrypt an api_key that is stored with encryption. I have registered the following hook: // Decrypt API key after it is retrieved add_filter('pre_option_percify_api_key', array( ...
0
votes
1answer
26 views

How to call do_action() to pass arguments to hooked functions that take different number of args?

Here is a simple example to explain my question. 3 functions are hooked into the myaction. Each take a different number of args and the args can be a number of an array of numbers. So args can also be ...
0
votes
1answer
29 views

What is the problem with these lines of code?

i am trying to add some content in the shop page of woocommerce. Just tried these codes... <?php add_action('woocommerce_archive_description' , 'sample' ); function sample() { echo "...
0
votes
0answers
15 views

How do I add a function to parent theme

I am looking for advice on how to add a function / hook to a parent theme. A colleague has installed a WordPress theme, but not child theme as I have tried adding a function to the child theme but ...
0
votes
0answers
37 views

Fail on admin_enqueue_scripts when I try it to upload a CSS file to my WordPress Plugin

I currently doing a WordPress Plugin and I am successful when I try to put CSS or JavaScript on the frontend but I don't know on where I fail when I trying to do the same on backend side, this is my ...
0
votes
0answers
40 views

Refresh Gutenberg with JS for it show updated post

I updated the post content after the saving. Let's say I am replace apple to banana. function apple_to_banana($content){ $content = str_replace('apple', 'banana', $content); return $content; } ...

1
2 3 4 5
44