Skip to product information
1 of 1

Agents Makers

Regular price €0,00 EUR
Regular price Sale price €0,00 EUR
Sale Sold out
Taxes included.

Text block

Description

This workflow automates the process of updating important Rank Math SEO fields (SEO Title, Description, and Canonical URL) directly via n8n. By leveraging a custom WordPress plugin that extends the WordPress REST API, this workflow ensures that you can programmatically manage SEO metadata for your posts and WooCommerce products efficiently. How it works: Sends a POST request to a custom API endpoint exposed by the Rank Math plugin. Updates SEO Title, Description, and Canonical URL fields for a specified post or product. Setup steps: Install and activate the Rank Math API Manager Extended plugin on WordPress. Provide the post or product ID you want to update in the workflow. Run the workflow to update the metadata automatically. Benefits: Full automation of SEO optimizations. Works for both standard posts and WooCommerce products. Simplifies large-scale SEO management tasks. Rank Math API Manager Extended plugin on WordPress &amplt?php /** * Plugin Name: Rank Math API Manager Extended v1.3 * Description: Manages the update of Rank Math metadata (SEO Title, SEO Description, Canonical URL) via the REST API for WordPress posts and WooCommerce products. * Version: 1.3 * Author: Phil - https://inforeole.fr */ if ( ! defined( 'ABSPATH' ) ) { exit; // Exit if accessed directly. } class Rank_Math_API_Manager_Extended { public function __construct() { add_action('rest_api_init', [$this, 'register_meta_fields']); add_action('rest_api_init', [$this, 'register_api_routes']); } /** * Registers the Rank Math meta fields in the REST API for posts and products (if WooCommerce is active). */ public function register_meta_fields() { $meta_fields = [ 'rank_math_title' =&ampgt 'SEO Title', 'rank_math_description' =&ampgt 'SEO Description', 'rank_math_canonical_url' =&ampgt 'Canonical URL' ]; // Register meta for posts by default. $post_types = ['post']; // If WooCommerce is active, add the 'product' post type. if ( class_exists('WooCommerce') ) { $post_types[] = 'product'; } foreach ( $post_types as $post_type ) { foreach ( $meta_fields as $key =&ampgt $description ) { register_post_meta( $post_type, $key, [ 'show_in_rest' =&ampgt true, 'single' =&ampgt true, 'type' =&ampgt 'string', 'auth_callback' =&ampgt [$this, 'check_update_permission'], 'description' =&ampgt $description, ] ); } } } /** * Registers the REST API route to update Rank Math meta fields. */ public function register_api_routes() { register_rest_route( 'rank-math-api/v1', '/update-meta', [ 'methods' =&ampgt 'POST', 'callback' =&ampgt [$this, 'update_rank_math_meta'], 'permission_callback' =&ampgt [$this, 'check_update_permission'], 'args' =&ampgt [ 'post_id' =&ampgt [ 'required' =&ampgt true, 'validate_callback' =&ampgt function( $param ) { return is_numeric( $param ) && get_post( $param ); } ], 'rank_math_title' =&ampgt [ 'type' =&ampgt 'string', 'sanitize_callback' =&ampgt 'sanitize_text_field', ], 'rank_math_description' =&ampgt [ 'type' =&ampgt 'string', 'sanitize_callback' =&ampgt 'sanitize_text_field', ], 'rank_math_canonical_url' =&ampgt [ 'type' =&ampgt 'string', 'sanitize_callback' =&ampgt 'esc_url_raw', ], ], ] ); } /** * Updates the Rank Math meta fields via the REST API. */ public function update_rank_math_meta( WP_REST_Request $request ) { $post_id = $request-&ampgtget_param( 'post_id' ); $fields = ['rank_math_title', 'rank_math_description', 'rank_math_canonical_url']; $result = []; foreach ( $fields as $field ) { $value = $request-&ampgtget_param( $field ); if ( $value !== null ) { $update_result = update_post_meta( $post_id, $field, $value ); $result[ $field ] = $update_result ? 'updated' : 'failed'; } } if ( empty( $result ) ) { return new WP_Error( 'no_update', 'No metadata was updated', ['status' =&ampgt 400] ); } return new WP_REST_Response( $result, 200 ); } /** * Checks if the current user has permission to update the meta fields. */ public function check_update_permission() { return current_user_can( 'edit_posts' ); } } new Rank_Math_API_Manager_Extended();

Key Features

1) Automates updates of Rank Math SEO fields for posts and products
2) Utilizes a custom WordPress plugin to extend the REST API for efficient SEO management
3) Supports automated POST requests to update SEO Title
Description
and Canonical URL
4) Works seamlessly with both standard WordPress posts and WooCommerce products
5) Simplifies large-scale SEO metadata management
6) Enhances overall SEO optimization process with full automation capabilities.

Required Tools

MetaobjectListDrop

View full details