Questions tagged [hooks]
Method by which plugins and themes extend core WordPress functionality.
630
questions with no upvoted or accepted answers
0
votes
0
answers
41
views
Is there any reason for the nested filters to be applied on the first case and not in the second one?
// This Works -> Filters are applied
add_action( 'current_screen', function(){
$type = get_current_screen()->post_type;
if(is_admin()){ // "true"
add_filter('...
0
votes
0
answers
136
views
Print on screen during shutdown hook - error during saving in theme-editor.php
I'm trying to use this sample php code added to my funcion.php file:
function echo_shutdown(){
echo 'test';
}
add_action( 'shutdown', 'echo_shutdown', 10 );
It works, i can see "test" at ...
0
votes
1
answer
251
views
Hook a script as the very last one before the closing body tag
I'm trying to add a script in the very last position before the closing via function.php
Other scripts are hooked by other plugins, so WP is placing my script as the firts one of the list. Like:
[my ...
0
votes
0
answers
23
views
Build a must-use plugin that tracks when other plugins are activated or deactivated
Here I am trying to utilize add_action to add a callback function to the hooked action of 'deactivate_plugin', but my function is not echoing as I expect.
$plugin = 'polls_plugin';<br>
function ...
0
votes
1
answer
404
views
Add action save post when create and publish
I try to use the hook save_post in my wp but I have a problem. I do this :
function when_save_post_match($post_id, $post){
if (isset($post->post_status) && 'auto-draft' == $post->...
0
votes
1
answer
149
views
Conditionally run function based on custom meta value?
I’m looking for a way to conditionally display an image within certain Woocommerce hooks that I choose based on whether a value is true within a custom meta field for the products on my site.
For ...
0
votes
0
answers
488
views
manage_shop_order_posts_custom_column() hook is Not working In Functions.php file in my WordPress active theme
As I added the manage_shop_order_posts_custom_column() hook in the functions.php file But the custom column post data not showing on the shop_order page.
manage_edit-shop_order_columns Filter is ...
0
votes
1
answer
27
views
Restrict editing of post type to list stored in user meta
What is the right action to invoke before a custom post type is getting edited in dashboard and contains the argument the post id? The url /wp-admin/post.php?post=282&action=edit&classic-...
0
votes
0
answers
140
views
Limiting actions only to edit.php page for specific custom post type
Excuse me if something like this has been asked before. So, I'm trying to alter the query which displays the posts of a custom post type, but on the admin side, more precisely, the edit.php page. This ...
0
votes
1
answer
175
views
Creating posts with links from a txt file
I have a script which scrapes articles from the web and saves the url to a .txt file. I've created a custom plugin which on activation, loops through the urls and creates a draft post with the content ...
0
votes
0
answers
274
views
WP_Query retuning empty array in rest api
I recently started writing a rest api for my plugin. I need to access some custom posts however WP_Query is returning an empty array when I'm querying the db.
There is the custom post type declaration....
0
votes
0
answers
24
views
Custom Header added within Dashboard pages, is this possible with custom template files?
I created a custom template and called it Header Home"header-home.php"
<?php
/**
* Template Name: Header Home
*/
?>
<?php
if( have_post() ) {
while( have_post() ){
...
0
votes
0
answers
73
views
save_post trigerred twice
I am trying to add more functionality to the update button. My end result is that I wish to call a python script but for now I am messing around with writing a log file. This is resulting in the log ...
0
votes
0
answers
49
views
Hooking after blog info update
I've been unsuccesfully looking for a way to hook into the "site information" update action. With "site information update", I mean when the blog's admin changes its title, ...
0
votes
1
answer
887
views
How to sort WooCommerce products page by latest in-stock items first?
How to sort the WooCommerce products page by latest in-stock items first and all the out-of-stock items to the last?
Currently, I'm using a code snippet from "https://www.businessbloomer.com/...
0
votes
1
answer
110
views
Hook to add_action('updated_option_my_option', [$this, 'save_data'], 10, 3]);
i want to modify my options data after save. Therefore i want to hook into "updated_option". This works without problem.
I create a new option called "my_update_option" and want ...
0
votes
1
answer
122
views
Warning at top of website & top menu gone
This warning has appeared at the top of our website, and our top menu bar has disappeared:
Warning: call_user_func_array) expects parameter! +~ be
a valid callback, function
'...
0
votes
1
answer
53
views
How to read and write session data?
My website requires users to complete their profile before they can place an order. So far, I have been able to redirect a user to his profile editing page if his profile is incompleted when he tries ...
0
votes
1
answer
1k
views
How to alter taxes amounts when updating an order
I'm developing a plugin based on WooCommerce to allow ordering gift boxes. Each box is a WooCommerce product composed by multiple "alternative products" (that are made from a custom post ...
0
votes
1
answer
496
views
Use a hook or filter, or overwrite this Gamipress function?
Currently, Gamipress allows you to import a CSV file that lists a username (email or ID), and a points value to add to the points type for that user. It uses this function to achieve this, which ...
0
votes
1
answer
358
views
How do I add a line break to a string that is output by PHP?
There is a heading output in my ad statistics page (WordPress):
<h3 id="ad-title"><?php printf( __( 'Statistics for %s', 'advanced-ads-tracking' ), $ad_name ); ?></h3>
I ...
0
votes
0
answers
33
views
WordPress How to reorder Page/Post Settings
I am trying to move Yoast Seo to the bottom of my Post/Page settings sidebar. I am not sure how to hook into those so I can change the order.
Order I need
Status & Visibility
Permalinks
...
0
votes
1
answer
33
views
Count when a post of a custom post type is deleted and store it in a theme option
I work on a website that shows products in a catalogue without checkout. Those products can be bougth stationary, and then the product will be deleted from a custom post type. So, I basically want to ...
0
votes
1
answer
31
views
Add hook after content without formatting
I want to add a table after the_content with a hook, but it's adding <p> tags in certain areas. This is a plugin, I don't want to remove <p> tags from all the_content, just the table I'm ...
0
votes
0
answers
460
views
Modify post slug before saving
I would like to modify the slug of new posts by adding text before and after the original slug. The slug is then sent over an API via a plugin that hooks into save_posts and transition_post_status.
...
0
votes
1
answer
142
views
Delay action unltil the untill previous (hoocked) action is completed
I'm quite new here so I hope you'll find my question documented enough. I've been digging into this for a while now, and haven't found satisfactory solutions, despites some looked relevant!
Basically, ...
0
votes
1
answer
511
views
How to add woocommerce products header title in woocommerce_breadcrumb hook to function.php
Iam new to WooCommerce theming and get stuck with category display page here is the code i have:
/**
* Change several of the breadcrumb defaults
*/
add_filter('woocommerce_breadcrumb_defaults', '...
0
votes
0
answers
60
views
Is there a way to Insert a post to post list?
In some websites or blogs (and mine too) they often have a list of their recent posts on their home page or top page. My idea is I'd like to insert one or some great posts that I'd like to highlight ...
0
votes
0
answers
406
views
Generate a QR code when creating a new WordPress user
I know that you can use the show_user_profile, edit_user_profile, personal_options_update and edit_user_profile_update to add and manage additional fields in user profiles.
In a site I'm developing, I ...
0
votes
0
answers
20
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
1
answer
212
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 ...
0
votes
2
answers
109
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
2
answers
52
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 ...
0
votes
0
answers
40
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
1
answer
87
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
0
answers
148
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
1
answer
55
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
0
answers
354
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
0
answers
57
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
0
answers
157
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
0
answers
199
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
1
answer
1k
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
0
answers
926
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
1
answer
926
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
1
answer
71
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
1
answer
38
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
0
answers
22
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
0
answers
50
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
0
answers
124
views
Best way to fix bad count on All | Mine | Published
I tweaked the default behavior of the post listing page (for a custom post type) via pre_get_posts, the thing is that now the count of All | Mine | Published isn't the right one.
I'm aware there is ...
0
votes
0
answers
379
views
Prevent header and footer from loading on specific pages with template or plugin
I am working on a client's site that has a few pages that are embedded into a mobile app through WebView. The goal is to prevent the header and footer from showing up on these certain pages. I can't ...