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

What does exactly GPL license mean for my WordPress theme?

Does this licensing scheme (for file groups) violates the WordPress license? No, only the PHP code needs to be GPL’d. A popular example is Thesis: http://mashable.com/2010/07/22/thesis-relents/ http://markjaquith.wordpress.com/2010/07/17/why-wordpress-themes-are-derivative-of-wordpress/ Do I have to publish the PHP code of the theme so it is available to everyone? You don’t have to publish it if your intention is to … Read more

Alert Email when any Post or Page is Changed

There’s a few plugins that handle email notifications, but they all seem to act like a subscription service for (all) WordPress users. To notify just you when a post or page is published: /** * Send an email notification to the administrator when a post is published. * * @param string $new_status * @param string … Read more

How to enqueue the style using wp_enqueue_style()

This is what you could do: 1 – Put the CSS in a separate file and save it in your theme directory. 2 – Add the following code in your functions php: function wpse_89494_enqueue_scripts() { if ( has_nav_menu( ‘secondary’ ) ) { wp_enqueue_style( ‘wpse_89494_style_1’, get_template_directory_uri() . ‘/your-style_1.css’ ); } if ( has_nav_menu( ‘primary’ ) ) … Read more

using wp_remote_get instead of file_get_contents [duplicate]

If you need to send a JSON response, then there’s a set of functions for that. In case you need that for an AJAX callback: wp_remote_retrieve_response_message() wp_remote_retrieve_response_code() wp_send_json_success() wp_send_json_error() wp_send_json() Would finally be something like that: $request = wp_remote_get( ‘http://example.com’ ); $response = wp_remote_retrieve_body( $request ); if ( ‘OK’ !== wp_remote_retrieve_response_message( $response ) OR 200 … Read more

Rewrite Slug for CPT Archive Pages to Plural Name of Slug

When you register the post type, set the argument ‘has_archive’ to a string, in your case plugins. The doc block for register_post_type() says: @type bool|string $has_archive Whether there should be post type archives, or if a string, the archive slug to use. Will generate the proper rewrite rules if $rewrite is enabled. Default false. Minified … Read more

wp_dequeue_style not working

Okay so I figured this one out. function custom_dequeue() { wp_dequeue_style(‘et-gf-open-sans’); wp_deregister_style(‘et-gf-open-sans’); } add_action( ‘wp_enqueue_scripts’, ‘custom_dequeue’, 9999 ); add_action( ‘wp_head’, ‘custom_dequeue’, 9999 ); @milo was right. The plugin was re-enqueueing it so the deregistering it got that file to stop loading. Then the plugin also had another check, where it would register and enqueue another … Read more