• Resolved catherinek

    (@catherinek)


    I’d like to add 410 redirections to deleted posts, possibly add it in the “after_delete_post” hook.
    Is there any documentation on this?

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author Rank Math SEO

    (@rankmath)

    Hello @catherinek

    Thank you for contacting the support and please accept our apologies for missing your support topic and thus the delayed response.

    Please try adding the following code in your theme’s functions.php file to create a redirection rule when a post is trashed:

    add_action( 'wp_trash_post', function( $post_id ){
    	$sources[] = [
    	    'pattern'    => get_the_permalink( $post_id ),
    	    'comparison' => 'exact',
    	];
    	$args = [
    	    'sources'     => $sources,
    	    'url_to'      => '',
    	    'header_code' => '410',
    	];
    	RankMath\Redirections\DB::add( $args );
    });

    Please let us know if that helps.

    Thread Starter catherinek

    (@catherinek)

    Right on! Thanks a lot!

    Plugin Author Rank Math SEO

    (@rankmath)

    Hello @catherinek

    We are super happy that this resolved your issue. If you have any other questions in the future, know that we are here to help you.

    If you don’t mind me asking, could you please leave us a review (if you haven’t already) on https://ww.wp.xz.cn/support/plugin/seo-by-rank-math/reviews/#new-post about your overall experience with Rank Math? We appreciate your time and patience.

    If you do have another question in the future, please feel free to create a new forum topic, and it will be our pleasure to assist you again.

    Thank you.

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘Any API/function to add redirection?’ is closed to new replies.