A name for an event that is executed at specific points throughout the WordPress core.

learn more… | top users | synonyms (2)

3
votes
4answers
12k views

How can I edit post data before it is saved?

I have a plugin and I would like to be able to run the post content through some filters before it is saved to the database. From looking at the plugin api, I see that two hooks that look like they ...
1
vote
1answer
38 views

How to filter content for specific content variable

I created a plugin that adds content from another post, and places this content next to the original content. I can say, that this content should appear at the bottom of the original post content. I ...
0
votes
1answer
28 views

Pass arguments to function class with do_action()

I'm trying to develop a "simple" script where i can create a filename with a timestamp of the last edit. For this I'm trying to code a class – but I'm having problems to pass an argument to add_action....
0
votes
1answer
49 views

Understanding and using did_action() in a conditional statement

I'm working with Genesis Framework in a custom theme, but this is not a question "genesis-specific". I need to populate the sidebar of my pages (not posts) conditionally. The condition is to check ...
1
vote
3answers
2k views

How do I hook a sidebar via add_action?

On one of my templates I have an action hook 'do_xyz' I want to attach a custom sidebar to the action hook do_xyz Here is what I am trying in my theme functions.php file, does not work: add_action('...
1
vote
0answers
22 views

Wordpress form. Variables to display on other page? [closed]

I'm using Ninja Forms, and I'm working on a form where when the users presses "ok" then the page is supposed to go to another page which shows specific information and links for that user. Right now ...
1
vote
1answer
34 views

Insert term when page is published - avoid duplicates after edits

So i want to dynamically add terms to a custom taxonomy named after new pages when these are published. Problem I have is that when you edit the page titles, another term will be added to the taxonomy....
33
votes
3answers
14k views

remove_action or remove_filter with external classes?

In a situation where a plugin has encapsulated its methods within a class and then registered a filter or action against one of those methods, how do you remove the action or the filter if you no ...
0
votes
1answer
26 views

save_post not triggered when a post is updated

I'm encountering something weird. I made a function on functions.php that I want to trigger when a post is saved or updated. function gh_set_inner_project_order($post_id){ $parent_id = ...
0
votes
1answer
27 views

Remove action added through function

A theme I'm using modified a woocommerce that I'd like undo in my child theme. It's been added as shown: function theme_setup(){ remove_action( 'woocommerce_before_main_content', '...
0
votes
2answers
70 views

How to get a single hook from wp_head()?

I am working on a custom post type and I don't want it to get all the clutter from wp_head(). However, I do want to show a specific hook, for example the YoastSEO meta tags. How do I call a specific ...
3
votes
3answers
4k views

Check if action hook exists before adding actions to it

I am trying to add a rel=next and rel=prev link tags to the head element of image.php template file. I have Wordpress SEO installed and I like to hook to this plugin wpseo_head action hook to achieve ...
0
votes
0answers
65 views

Filters, priority when run after plugins_loaded

In my main plugin I filter the_content to add rich snippets. Something like this: add_filter('the_content', 'add_schema'); function add_schema( $content ) { $schema = NULL; //To avoid undefined ...
1
vote
1answer
40 views

Wait a result before enqueue

Supposing we have : class AwesomeClass{ private storedResult; private __construct(){ add_action( 'set_logged_in_cookie', array($this, 'a'),10,1); add_action('...
0
votes
1answer
24 views

previous_post_link inside of a function?

I'm missing something on how to call previous_post_link() inside of a function. I also tried assigning the output to a string variable and using that. function prevnext( $content ) { $content .= '...
0
votes
2answers
94 views

How to pass parameters to admin_notices?

So there is the following case. I need to display a name inside of admin_notices. class MyPlugin_Admin { public static function render_admin_notice() { echo $name . ' has been upgraded.';...
4
votes
1answer
246 views

How to do_action and get a return value?

So there is the following scenario. I add an action to clean logs from the database: add_action( 'myplugin_clean_logs', array( 'MyPlugin_Logs', 'clean_logs' ) ); Now I want to run this action ...
0
votes
0answers
34 views

Run javascript code after “woocommerce_payment_complete” action hook

I am trying to fire custom javascript code after successful payment in woocommerce. Code that I use so far: add_action( 'woocommerce_payment_complete','mysite_woocommerce_payment_complete' ); ...
0
votes
1answer
53 views

Why doesn't a form need an 'action' with a plugin that uses the post data?

So I'm still rather new to WordPress plugins. And there's one thing that I'm not sure of. I'm building a front-end form that allows users to post posts. In this guide down below there's a plugin made ...
0
votes
1answer
31 views

I can't enqueue Suggest.js in frontend - not added

my suggest.js is not being added in front-end. All scripts are correctly loaded but this one. I want to load it only on frontpage so: add_action('wp_enqueue_scripts', 'homescripts'); function ...
17
votes
4answers
12k views

How to know what functions are hooked to an action/filter?

Is there a way to know what functions are hooked to a particular hook? For example if I'd like to know what functions are hooked to the wp_head hook.
0
votes
0answers
24 views

register_nav_menu & add_action & in AJAX callback

Is it possible to call add_action or register_nav_menu in AJAX callback? I.e. add_action('wp_ajax_some_ajax_action','ajax_callback'); function ajax_callback(){ register_nav_menu('some-location','...
0
votes
2answers
464 views

widgets_init actions not fired from functions.php's child theme

I need to add new sidebars for using them accordingly on different pages throughout my shop. I use Woocommerce and my own Storefront child theme. This is a snippet of what is in functions.php file ...
0
votes
0answers
46 views

remove_action not working with procedural function

I have a purchased theme that procedurally loads an action like this: function func() { echo "head content"; } add_action( 'wp_head', 'func', 5 ); Following the remove action codex I tried the ...
3
votes
1answer
30 views

When should I call add_settings_section and add_settings_field?

All of the examples I've seen for add_settings_section & add_settings_field have them being called on the admin_init action. This means that they're being called when loading every single admin ...
0
votes
1answer
21 views

'Conflict' with action deleted_post and is_admin()

I created a delete button on frontend for blog posts and custom type posts and I would redirect to a specific page after deleting them, I looked around on google and I found all solutions like this: ...
3
votes
1answer
474 views

Check php version before theme activation

I've got theme that requires php 5.3+ version. If older - fatal error occurs with it. So what I need to do when user try to activate this theme is to check php version before going into theme code ...
1
vote
1answer
2k views

Using several add_action with parameters inside a class

I'm creating a theme framework and using a class to initiate all basic function of the theme (adding theme support, menus, etc). I've got stuck when I tried to enqueue the scripts and styles though: ...
3
votes
2answers
107 views

WP Schedule Event - Every Day When First Visitor Comes

I have a daily wp schedule event. I know that it happens when a user visits the site and if a schedule time passes. If I started it on today 12 a.m. and if tomorrow first visitor comes tomorrow 1:...
3
votes
1answer
2k views

Add something to beginning of the content

I'm using add_action('the_content', 'myFunction', 10) to append data to the end of the content. How can I place content at the beginning of the content?
0
votes
1answer
17 views

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 ...
0
votes
2answers
27 views

Dequeue, Unregister, Remove Action - Not Working on Plugin

Several years ago, not really having a handle on the best practice for running a MultiSite network, I often network activated plugins. Later I realized this was a mistake because not all the sites ...
1
vote
2answers
68 views

Remove Action from Plugin within extended class and no assigned variable

I have tried so many solutions for this but I can't figure it out. Here is a simplified version of the plugin code: class YITH_Vendors_Frontend_Premium extends YITH_Vendors_Frontend { public ...
1
vote
2answers
5k views

add_action and wp_head not display content in head section

I have a big problem. In a Wordpress page I've a function that generate og meta tags. I want to "append" that generated meta in the head section. So, I write this code: add_action('wp_head', '...
1
vote
1answer
69 views

Why Should We Use wp_clear_scheduled_hook and What it Does?

I am new to cron job. After reading this article I was able to run a function every hour using wp_schedule_event. There is a quote on "Don't forget to clean the scheduler on deactivation" in that ...
4
votes
4answers
208 views

What is a good way to pass a variable from add_action to a Theme?

Inside functions.php: add_action('init','my_action'); function my_action() { if($dontknow) { $passme = "yes"; } else { $passme = "no"; } } Inside index.php of the ...
2
votes
2answers
412 views

Detect type of post status transition

I have a function on my site that it supposed to run when a new post is published (email push notification), with the exception of the same article updated (i.e publish_to_publish transition, I don't ...
0
votes
0answers
47 views

How do I output the returned value of a function that uses an earlier hook?

If I define a function that retrieves a value within an action hook and returns it, what is the best way to call the function in a later hook? My general aim is to write reusable functions with ...
0
votes
0answers
24 views

Order categories input fields

I am using: add_action('category_add_form_fields', array ($this, 'add__form_fields'), 10, 2); To add an extra field in the categories form, it is possible to choose the position of this new field? ...
0
votes
3answers
3k views

How do I add some javascript validation to the admin interface form's onsubmit?

I have a plugin that adds meta boxes to the admin interface and I need to do some validation when the user presses the "update" button before the form is submitted. Is there a WordPress action or ...
1
vote
1answer
47 views

WooCommerce add_action hook results in 500 error

I am trying to add a line of text on the checkout page of the store that will go immediately after shipping row. I added the following to my child theme functions.php file: add_action( '...
0
votes
4answers
135 views

How to prepend to the_title for admin-side plugin's use

When I do this: function append_album_review_to_title( $title ) { global $post; if ( get_post_type( $post->ID ) == 'album_review' && in_the_loop() ){ return 'Album Review: '...
0
votes
1answer
71 views

Apply the_title filter to post titles AND backend auto social-sharing plugin, but not nav menu

The Challenge I have been trying to write a filter that applies (prepends a string) to (a) post titles of a certain post type and (b) to that same post type WordPress admin backend for use by an auto ...
0
votes
2answers
49 views

How to cancel an action hooked to untrash_post? or any hook

I want to do the following in a plugin: - hook to untrash_postwith a custom function - do some checking inside custom function - cancel actual post restoring (untrashing) I've tried with ...
0
votes
1answer
29 views

Is it possible to completely replace a post with an action/filter?

Currently I am trying to replace the $post global with another dynamically loaded post in the wp action. However, while even in the templates the correct post data shows when outputting $post, the ...
0
votes
1answer
33 views

Custom Form Processing Issue

I have created a form on my wordpress site, a function to process the data located in functions.php, and an action php file. I have tested the processing function and know it works, but I'm having ...
1
vote
1answer
58 views

Modify custom field input data before creating a new post

I'm try to check input data before it is added to DB. For example: I have a custom post meta named book_isbn in post page. I want to make sure that this variable $_POST['book_isbn'] is valid before ...
0
votes
1answer
103 views

How to stop or remove an action being called inside a function of an extended class

The Problem I am trying to remove an JSON+LD block being added by a WordPress plugin called The Events Calendar. I believe it is being added by the function called: ...
0
votes
2answers
38 views

How to add custom post meta to default blog post?

I have a code which calculates estimated reading time of a blog post (feel free to use it as you wish): function estimated_reading_time( $post ) { $words = str_word_count( strip_tags( $post->...
0
votes
0answers
16 views

how to init wordpress env from within custom script

I know you can run a php script using the wp-cli command which will init the wp env for you as discussed here Initialize WordPress environment to use in command line script but what I want to do is ...