How to intercept a 404 error

As was mentioned in a comment, template_redirect would be an appropriate hook for intercepting a 404 before the template is loaded. function wpd_do_stuff_on_404(){ if( is_404() ){ // do stuff } } add_action( ‘template_redirect’, ‘wpd_do_stuff_on_404’ ); Refer to the Action Reference for the general order of actions on the front end. The main query runs between … Read more

How many times can I hook into the same action?

WordPress hooks work like Hollywood: you don’t call them, they call you. But unlike Hollywood, they keep calling everyone on the list. It’s normal for an action or a filter to have multiple functions hooked to it, from different plugins, or even just different functions in the WordPress core that all do something specific. It … Read more

Hooking in to plugins

@Ryan Elkins: I guess the answer depends on how import each use-case is to you. In some cases it would be something you need quick-and-dirty, in others it might be a more significant use-case. Here are the two things that come to mind: Look for Alternate Hooks within WordPress Core If it’s something quick and … Read more

Changing the “Plugin Activated” Message Default

You can try this: is_admin() && add_filter( ‘gettext’, function( $translated_text, $untranslated_text, $domain ) { $old = array( “Plugin <strong>activated</strong>.”, “Selected plugins <strong>activated</strong>.” ); $new = “Captain: The Core is stable and the Plugin is <strong>activated</strong> at full Warp speed”; if ( in_array( $untranslated_text, $old, true ) ) $translated_text = $new; return $translated_text; } , 99, … Read more

Use wp init hook to call other hooks?

In general: Yes, wait for a dedicated hook to start your own code. Never just throw an object instance into the global namespace. But init is rarely necessary. You hook in as late as possible. If your first code runs on wp_head do not use an earlier hook. You can even cascade hooks: add_action( ‘wp_head’, … Read more

get $post in init filter or action?

Turns out the answer was simply to use url_to_postid like this: $keyword = get_post_meta( url_to_postid( “http://”.$_SERVER[‘SERVER_NAME’].$_SERVER[‘REQUEST_URI’] ), ‘_wpg_def_keyword’, true ); Works perfectly even from init.

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)