Who is this workflow for? Efficiently manage and update your WordPress and WooCommerce SEO metadata with this n8n workflow. By leveraging a custom WordPress plugin that extends the REST API, this workflow automates the updating of Rank Math SEO fields—SEO Title, Description, and Canonical URL—for your posts and products..

What does this workflow do?

  • Trigger Setup:
  • The workflow begins with a webhook or schedule trigger in n8n, determining when the SEO update should occur.
  • Retrieve Target Content:
  • Specify the post or product ID that needs its SEO fields updated. This can be dynamically sourced from a datastore like Google Sheets or GitHub.
  • HTTP Request to Custom API:
  • An HTTP Request node sends a POST request to the custom API endpoint (rank-math-api/v1/update-meta) provided by the Rank Math API Manager Extended plugin.
  • Update SEO Metadata:
  • The API processes the request, updating the SEO Title, Description, and Canonical URL for the specified content.
  • Confirmation and Logging:
  • The workflow receives a response indicating the success or failure of each metadata update. This information can be logged to platforms like Google Sheets or sent via WhatsApp for notifications.
  • Error Handling:
  • Implement error handling to manage any issues during the update process, ensuring reliability and consistency.
  • Install the Plugin:
  • Add the above PHP code as a new plugin in your WordPress installation.
  • Activate the plugin through the WordPress admin dashboard.
  • Configure the Workflow in n8n:
  • Webhook Node: Set up a trigger for when the SEO update should occur.
  • HTTP Request Node: Configure it to send a POST request to https://yourwordpresssite.com/wp-json/rank-math-api/v1/update-meta with the required parameters (post_id, rank_math_title, rank_math_description, rank_math_canonical_url).
  • Additional Nodes: Integrate with tools like Google Sheets or WhatsApp for logging and notifications as needed.
  • Run the Workflow:
  • Initiate the workflow manually or set it to trigger automatically based on your configuration.
  • The specified SEO fields will be updated for the targeted post or product.

By following these steps, you can automate and manage your SEO metadata efficiently, ensuring your WordPress site and WooCommerce products are always optimized.

🤖 Why Use This Automation Workflow?

  • Time-Saving Automation: Eliminate manual updates by automating SEO field modifications.
  • Consistency: Ensure uniform SEO metadata across all your content and products.
  • Scalability: Easily manage large volumes of posts and products without additional effort.
  • Integration: Seamlessly works with existing tools like WordPress, WooCommerce, and Rank Math.

👨‍💻 Who is This Workflow For?

This workflow is ideal for:

  • Content Managers: Streamline SEO tasks for blog posts.
  • E-commerce Managers: Maintain consistent SEO metadata for WooCommerce products.
  • Developers: Integrate automated SEO updates into existing workflows.
  • Digital Marketers: Enhance SEO efficiency and effectiveness without manual intervention.

🎯 Use Cases

  1. Bulk SEO Updates: Automatically update the SEO titles and descriptions for hundreds of blog posts or products.
  2. Dynamic Content Management: Adjust SEO metadata based on real-time data changes or specific triggers.
  3. SEO Optimization Campaigns: Implement large-scale SEO improvements effortlessly across multiple content types.

TL;DR

This n8n workflow automates the updating of Rank Math SEO fields for WordPress posts and WooCommerce products, enhancing your SEO management efficiency. By integrating a custom WordPress plugin with n8n, you can programmatically control and maintain your SEO metadata, ensuring consistency and scalability across your website.

Rank Math API Manager Extended Plugin

To enable the workflow, install and activate the following custom WordPress plugin:

<?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' => 'SEO Title',            'rank_math_description' => 'SEO Description',            'rank_math_canonical_url' => '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 => $description ) {                register_post_meta( $post_type, $key, [                    'show_in_rest' => true,                    'single' => true,                    'type' => 'string',                    'auth_callback' => [$this, 'check_update_permission'],                    'description' => $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' => 'POST',            'callback' => [$this, 'update_rank_math_meta'],            'permission_callback' => [$this, 'check_update_permission'],            'args' => [                'post_id' => [                    'required' => true,                    'validate_callback' => function( $param ) {                        return is_numeric( $param ) && get_post( $param );                    }                ],                '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 via the REST API.     */    public function update_rank_math_meta( WP_REST_Request $request ) {        $post_id = $request->get_param( 'post_id' );        $fields = ['rank_math_title', 'rank_math_description', 'rank_math_canonical_url'];        $result = [];        foreach ( $fields as $field ) {            $value = $request->get_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' => 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();?>

Help us find the best n8n templates

About

A curated directory of the best n8n templates for workflow automations.