Method by which plugins and themes extend core WordPress functionality.

learn more… | top users | synonyms

27
votes
1answer
6k views

Where is the right place to register/enqueue scripts & styles

I am using WordPress 3.1.4 by now. I am confused with where (which hook) do I use: to register and/or enqueue scripts and styles on front- and back-ends? Questions: Which are right hooks to ...
26
votes
6answers
5k views

Where Can I Find a List of WordPress Hooks?

Where can I find a list of all the WordPress hooks and over-ridable functions (pluggable, scriptable, etc)? Edit: Plugin is here: ...
22
votes
1answer
5k views

Passing a parameter to filter and action functions

Is a way to pass my own parameters to the function in add_filter or add_action. For example take a look in the following code: function my_content($content, $my_param) { do something... using ...
15
votes
2answers
6k views

Difference Between Filter and Action Hooks?

I have been looking at the plugin API a bit more in depth recently and I was wondering what real differences there were between action and filter hooks. They both are events that receive data as a ...
12
votes
2answers
393 views

How do filters and hooks really work in PHP

How does filters and hooks actually work in WordPress? I'm asking about something advanced. How is it implemented in PHP? E.g how does it collect all the hooks from the different plugins and "attach" ...
12
votes
3answers
2k views

How to add Custom Blog Options to new blog setup form?

Seems like a simple enough requirement, but I'm struggling: I want to add an option field to the "Add New Site". A simple text option is fine. How do I do this? I need to save this custom blog ...
12
votes
5answers
3k views

How to include code only on specific pages?

I'm learning about plugins and shortcodes. I noticed that when I activate my plugin its code gets loaded on all of my pages-- even pages that don't have my shortcode. (I don't mean content vs. admin ...
11
votes
3answers
1k views

get_template_part vs action hooks in themes

It seems to me both of these afford the opportunity for the end user to modify a theme without actually editing the themes files (via child themes). My question is, is one method preferred over the ...
11
votes
5answers
2k views

How do you use a CPT as the default home page?

I have a client who's site will be making heavy use of custom post types to configure their site. But I'm between a rock and a hard place for their requested home page. In reality, the home page ...
10
votes
1answer
5k views

how to limit search to post titles?

Is there a way to limit search to post titles? I know I can modify query.php core file but there must be a way to do it with hooks right? Thanks in advance!
10
votes
4answers
731 views

Hooking in to plugins

I'm working on a plugin that would ideally be able to do things when a user does something through a different plugin. I can add custom hooks in those plugins but obviously this wouldn't work well ...
10
votes
2answers
336 views

Hierarchical taxonomy UI

I don't like the way the taxonomies are displayed within the Wordpress admin and was wondering if anyone knew the best way to hook in and change it. Currently if I select some terms within my post ...
9
votes
2answers
2k views

Why do some hooks not work inside class context?

I'm pretty stumped on this one. I'm using add_action inside my plugin class to do certain things- add scripts & styles to the head, wp_ajax, etc. Here's the actions, in the __construct: function ...
8
votes
4answers
6k views

Theme Activate Hook

I would like to write a function to email me the URL of the website when my theme is activated. What is the hook initiated when the theme is activated?
8
votes
2answers
6k views

How to hook update_post_meta and delete_post_meta?

I'm still struggling to get my head around this whole hooking into things, so I'm really stuck on trying to do the following task: If update_post_meta is fired then check to see if the meta_key is ...
8
votes
3answers
5k views

How to enqueue scripts on custom post add/edit pages?

I'm trying to enqueue a JS script only when someone is adding or editing a custom post type I created called "recipes". Currently the script works ok when I do this: if (is_admin()){ ...
8
votes
2answers
4k views

Use wp init hook to call other hooks?

I want to know if it is a good practice according to WordPress theme or plugin development. add_action('init','all_my_hooks'); function all_my_hooks(){ // some initialization stuff here and then ...
8
votes
1answer
944 views

Registering Class methods as hook callbacks

I'm not sure if I have done this correctly. As I understand it: if I have a class foo and a static method bar I can register that as the callback by passing the array array("foo","bar") as the ...
7
votes
3answers
3k views

Are there any hooks that alter the 404 logic?

Provided you have a 404 page defined in your theme, Wordpress will display a 404 page if "tag" is defined in $wp_query->query_vars, and there are no posts matching that tag. I'm writing a plugin that ...
6
votes
4answers
3k views

Import Wordpress XML File from Within Functions.php

I am developing a theme which has a different method of adding in content and so, the default install of Wordpress won't show any content because of this. I was wondering if it is possible to ...
6
votes
3answers
4k 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.
6
votes
2answers
694 views

Action hook for custom tax edit

So, i have a function in my template file functions.php which cache a search form that contain a custom taxonomie terms. I want to flush cache (or delete one cache group) when I add/delete/edit terms ...
6
votes
2answers
6k views

Is there a hook that runs after a user logs in?

I am writing a plugin that fetches some extended user info from a remote service and I need it to execute its function each time a user logs in. Is there a hook that gets fired after login that I can ...
6
votes
4answers
7k views

Auto-retrieve YouTube Image for Thumbnail?

I have a custom post type that accepts a YouTube embed HTML snippet, title, and a featured image. Currently, I'm going and finding an image for the featured image, but ideally I would be able to ...
6
votes
1answer
10k views

Wordpress hooks/filters insert before content or after title

trying to insert content before the post content in my functions.php - I know how to use the regular wp hooks, but unsure how to insert into other areas. Tried this, but it kills content on any other ...
6
votes
3answers
4k views

Calling a Function After New Post Creation for a WordPress Custom Post Type?

Assume I created a new post type 'product'. Is there a way to perform a function (user created) when this new 'product' post has been created?
6
votes
3answers
1k views

Making Custom Fields Standard in the Admin UI

I've added a few different custom_post_types to my Wordpress 3 installation. They are all a bit different from eachother, and should store unique information in custom_fields. But while one may store ...
6
votes
1answer
799 views

Whats worth using add_action when we can simply use add_filter?

I've just looked into wordpress code and found this definition of add_action: function add_action($tag, $function_to_add, $priority = 10, $accepted_args = 1) { return add_filter($tag, ...
6
votes
2answers
330 views

Wordpress and event-driven programming - what is it about?

I want to state very clearly that this does not intend to revive the discussion about functional/procedural programming versus object-oriented programming. There is plenty said about that, on WPSE and ...
6
votes
2answers
1k views

Extract image from content and set it as the featured image

The problem: I'm posting from the Wordpress iPhone app. When adding an image, the image shows up in the description itself, which I don't like. What I'm trying to do: Remove the image from the ...
5
votes
4answers
652 views

Is there a limit to hook priority?

When I wish my filter or action hook to override all others, I will assign it a priority of 999. However, lately I have been seeing some people use extreme values for the priority, such as 20000, and ...
5
votes
2answers
112 views

Valid characters for actions, hooks and filters

I haven't ever seen a tag such as do_action('something_10'). Is it invalid if I use numbers? If the method is valid, how can I write different numbers in the tag string conditionally? For example, is ...
5
votes
2answers
2k views

Save_post for custom post type?

Is there a save_post hook for custom post types? example: save_my_post_type I know there is publish_my_post_type but I'm looking for a save hook.
5
votes
1answer
70 views

Do WordPress Core Filenames Work as Hooks?

This is in reference to another answer here on wordpress.stackexchange. The answerer used the filename as the hook to enqueue scripts and styles to certain pages. add_action( ...
5
votes
2answers
237 views

Is there any debug toolbar that shows whick hooks are called for the current page in Wordpress?

In Django there is a debug toolbar that shows which template files and hooks are called while rendering a page. Is there any plugin that shows which hooks are called for the current page in ...
5
votes
4answers
4k views

Is there a way to set default custom fields when creating a post?

When I'm creating a new post, just after clicking "Add New", when the post editor shows, instead of having to use the dropdown and choose a custom field to use, I'd like to have some default custom ...
5
votes
2answers
2k views

Earliest hook to reliably get $post/$posts

What's the earliest possible action I can hook into where I'll be able to access the global $post/$posts variables on both the front and back ends? I've tried looking through the Codex reference, Adam ...
5
votes
3answers
2k views

Changing Plugin Load Order

I'm writing a plugin, bar, which is dependent on another plugin, foo, being activated, and I need the functions from foo to be available when bar loads. Normally plugins are loaded in alphabetical ...
5
votes
1answer
590 views

Hook that fires when admin setting is saved

Is there any specific hook that fires when admin setting is saved. I have cached some data from admin back-end setting menu. Now i want to the delete the caching when setting saved in admin menu. ...
5
votes
1answer
2k views

get $post in init filter or action?

It seems that $post is only available to hooks executing at certain times. I have an "init" hook that needs to pull some data from the database using the $post->ID. So far my only workaround has ...
5
votes
1answer
2k views

Difference between do_action and add_action

This question might be wrong, I am not sure about it. Because I am not clear on this. I know add_action it is used to to hook our function to the specified function. For example ...
5
votes
1answer
41 views

Wordpress Multisite: Adding actions to only one site

I have Wordpress Multisite installed with WooCommerce network activated. I want to add an action to a hook in ONE of the sites that has WooCommerce installed, instead of all of them. For example, I ...
5
votes
1answer
544 views

Hook into WordPress update?

I'd like to know if there's any way to hook into WordPress update process and send $_POST variable to update server? I'm delivering plugin/theme updates from private server and I hook into this: ...
4
votes
3answers
6k views

add_action hook for completely new post?

publish_post Runs when a post is published, or if it is edited and its status is "published". Action function arguments: post ID. -Plugin API Documentation I've added the publish_post ...
4
votes
5answers
675 views

Implementing advanced add_* function wrappers

add_action() and add_filter() are major functions. However in some scenarios add one more function and hook it somewhere approach gets bulky and inconvenient. I had determined for myself several use ...
4
votes
3answers
3k views

Which hook should be used to add an action containing a redirect?

I want to build a plugin that grabs certain url params from the query string to build a new query string for the same page. I'm following the excellent the Professional WordPress Plugin Development ...
4
votes
1answer
181 views

Changing the “Plugin Activated” Message Default

Whenever an administrator in WordPress activates a plugin, upon the reload of the plugin page, a notice will appear upon successful activation reporting "Plugin Activated". Is there a way to change ...
4
votes
2answers
10k views

How to customize woocommerce related products?

I have the following lines of code in my website that will display the related products at the bottom of my single product page in WooCommerce... functions.php: // display upsells and related ...
4
votes
1answer
138 views

Hook when category is added to post

I'm trying to do something when a category is added to post and saved. I thought that using the save_post hook would have registered when a category is added to a post, but it doesn't appear to. When ...
4
votes
3answers
5k views

Hook for post and page load

I need to run a function when a particular post or page is loaded. Is there any hook that lets me check whether a post is being displayed during page load ?