Skip to main content

Automate Rank Math SEO field updates for Wordpress or Woocommerce

Workflow preview

Workflow preview
100%
Automate Rank Math SEO field updates for Wordpress or Woocommerce preview
Open on n8n.io

Important notice

This workflow is provided as-is. Please review and test before using in production.

1. Workflow Overview

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...

Best for

  • Market Research automation workflows
  • beginner n8n builders looking for reusable templates

Tools used

n8n-nodes-base.set, n8n-nodes-base.manualtrigger, n8n-nodes-base.httprequest

Source and attribution

This workflow is cataloged by N8N Workflows and links back to its original n8n.io source page by phil.

Original n8n.io source

1.1 Workflow description

Title
Automate Rank Math SEO field updates for Wordpress or Woocommerce
Workflow name
Automate Rank Math SEO field updates for Wordpress or Woocommerce

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.

Bulk version available here.

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.

To understand exactly how to use it in detail, check out my comprehensive documentation here.

Rank Math API Manager Extended plugin on WordPress

// ATTENTION: Replace the line below with <?php - This is necessary due to display constraints in web interfaces.

<?php
/**
 * Plugin Name: Rank Math API Manager Extended v1.4
 * Description: Manages the update of Rank Math metadata (SEO Title, SEO Description, Canonical URL) via a dedicated REST API endpoint for WordPress posts and WooCommerce products.
 * Version: 1.4
 * 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_api_routes']);
    }

    /**
     * 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'             => 'POST',
            'callback'            => [$this, 'update_rank_math_meta'],
            'permission_callback' => [$this, 'check_route_permission'],
            'args'                => [
                'post_id' => [
                    'required'          => true,
                    'validate_callback' => function( $param ) {
                        $post = get_post( (int) $param );
                        if ( ! $post ) {
                            return false;
                        }
                        $allowed_post_types = class_exists('WooCommerce') ? ['post', 'product'] : ['post'];
                        return in_array($post->post_type, $allowed_post_types, true);
                    },
                    'sanitize_callback' => 'absint',
                ],
                'rank_math_title' => [
                    'type'              => 'string',
                    'sanitize_callback' => 'sanitize_text_field',
                ],
                'rank_math_description' => [
                    'type'              => 'string',
                    'sanitize_callback' => 'sanitize_text_field',
                ],
                'rank_math_canonical_url' => [
                    'type'              => 'string',
                    'sanitize_callback' => 'esc_url_raw',
                ],
            ],
        ] );
    }

    /**
     * Updates the Rank Math meta fields for a specific post.
     *
     * @param WP_REST_Request $request The REST API request instance.
     * @return WP_REST_Response|WP_Error Response object on success, or WP_Error on failure.
     */
    public function update_rank_math_meta( WP_REST_Request $request ) {
        $post_id = $request->get_param('post_id');
        
        // Secondary, more specific permission check.
        if ( ! current_user_can('edit_post', $post_id) ) {
            return new WP_Error(
                'rest_forbidden',
                'You do not have permission to edit this post.',
                ['status' => 403]
            );
        }

        $fields  = ['rank_math_title', 'rank_math_description', 'rank_math_canonical_url'];
        $results = [];
        $updated = false;

        foreach ( $fields as $field ) {
            if ( $request->has_param( $field ) ) {
                $value = $request->get_param( $field );
                $current_value = get_post_meta($post_id, $field, true);

                if ($current_value === $value) {
                     $results[$field] = 'unchanged';
                } else {
                    $update_status = update_post_meta( $post_id, $field, $value );
                    if ($update_status) {
                        $results[$field] = 'updated';
                        $updated = true;
                    } else {
                        // This case is rare but could indicate a DB error or other failure.
                        $results[$field] = 'failed'; 
                    }
                }
            }
        }

        if ( ! $updated && empty($results) ) {
            return new WP_Error(
                'no_fields_provided',
                'No Rank Math fields were provided for update.',
                ['status' => 400]
            );
        }

        return new WP_REST_Response( $results, 200 );
    }

    /**
     * Checks if the current user has permission to access the REST API route.
     *
     * @return bool
     */
    public function check_route_permission() {
        return current_user_can( 'edit_posts' );
    }
}

new Rank_Math_API_Manager_Extended();

Bulk version available here. : this bulk version, provided with a dedicated WordPress plugin, allows you to generate and bulk-update meta titles and descriptions for multiple articles simultaneously using artificial intelligence. It automates the entire process, from article selection to the final update in Rank Math, offering considerable time savings. .


Phil | Inforeole | Linkedin

🇫🇷 Contactez nous pour automatiser vos processus

1.2 Logical Blocks

This catalog entry is organized from the workflow JSON. The node-level section below shows the executable blocks available for review before importing the template.

2. Block-by-Block Analysis

Block 1 - Settings

Type / Role
n8n-nodes-base.set - set
Config choices
Version 3.4

Block 2 - When clicking ‘Test workflow’

Type / Role
n8n-nodes-base.manualTrigger - manualTrigger
Config choices
Version 1

Block 3 - HTTP Request - Update Rank Math Meta

Type / Role
n8n-nodes-base.httpRequest - httpRequest
Config choices
Version 4.2

3. Summary Table

Workflow Automate Rank Math SEO field updates for Wordpress or Woocommerce
Complexity beginner
Nodes 3
Categories Market Research
Author phil
Published 02 Feb 2025

4. Reproducing the Workflow from Scratch

  1. 1. Download the workflow JSON

    Use the JSON export at /data/workflows/2836/2836.json as the source template for this automation.

  2. 2. Import the template into n8n

    Open n8n, import the downloaded JSON, and review each node before activating the workflow.

  3. 3. Configure credentials and variables

    Replace placeholder credentials, API keys, webhook URLs, account IDs, and environment-specific values with your own settings.

  4. 4. Test with sample data

    Run the workflow manually or in a staging workspace, inspect node output, and confirm downstream systems receive the expected data.

  5. 5. Activate and monitor

    Enable the workflow only after testing, then monitor executions, errors, and rate limits during the first production runs.

5. General Notes & Resources

Review imported nodes carefully before activation. This catalog entry is intended to help you inspect the workflow structure, understand required services, and find related templates faster.

Node names, credentials, schedules, webhook paths, and external service limits may need adjustment for your workspace.

Frequently asked questions

What does Automate Rank Math SEO field updates for Wordpress or Woocommerce do?

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...

What do I need before importing this workflow?

Review the workflow JSON, configure any required credentials in n8n, and test the automation in a safe workspace before using it in production.

Can I customize this workflow?

Yes. Use the block-by-block analysis and the downloadable JSON to inspect each node, then adjust credentials, prompts, schedules, filters, or destinations for your Market Research use case.