{"id":9661,"date":"2025-07-28T09:25:45","date_gmt":"2025-07-28T07:25:45","guid":{"rendered":"https:\/\/inforeole.fr\/?p=9661"},"modified":"2025-07-28T09:25:46","modified_gmt":"2025-07-28T07:25:46","slug":"rankmath-wordpress-api","status":"publish","type":"post","link":"https:\/\/inforeole.fr\/rankmath-wordpress-api\/","title":{"rendered":"Mettre \u00e0 jour vos champs SEO Rank Math avec n8n"},"content":{"rendered":"\n<p>Par d\u00e9faut, l&rsquo;API REST de WordPress n&rsquo;expose pas les champs <strong>SEO de Rank Math<\/strong>, tels que le titre SEO, la m\u00e9ta-description ou l&rsquo;URL canonique. Cette absence de point d&rsquo;acc\u00e8s natif bloque toute modification programmatique, ce qui constitue un obstacle majeur pour l&rsquo;automatisation des strat\u00e9gies SEO. Cette limitation est particuli\u00e8rement probl\u00e9matique \u00e0 l&rsquo;\u00e8re du GEO (Generative Engine Optimization), o\u00f9 l&rsquo;optimisation pour les moteurs de r\u00e9ponse et les LLMs devient un enjeu concurrentiel.<\/p>\n\n\n\n<p>La solution consiste \u00e0 impl\u00e9menter un plugin WordPress personnalis\u00e9 qui enregistre un point de terminaison (endpoint) d\u00e9di\u00e9 au sein de l&rsquo;API REST. Ce point de terminaison agit comme une passerelle, permettant un acc\u00e8s en lecture et en \u00e9criture aux champs de Rank Math qui sont normalement inaccessibles.<\/p>\n\n\n\n<p>Avec ce connecteur en place, des plateformes d&rsquo;automatisation comme n8n peuvent \u00eatre utilis\u00e9es pour programmer des mises \u00e0 jour des donn\u00e9es SEO. Ceci permet le d\u00e9ploiement de strat\u00e9gies avanc\u00e9es, telles que :<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>La mise \u00e0 jour en masse des m\u00e9tadonn\u00e9es pour des produits WooCommerce.<\/li>\n\n\n\n<li>L&rsquo;automatisation du SEO pour des types de contenu personnalis\u00e9s (custom post types).<\/li>\n\n\n\n<li>L&rsquo;ajustement dynamique des titres et descriptions pour cibler des requ\u00eates conversationnelles, une pratique essentielle en GEO.<\/li>\n<\/ul>\n\n\n\n<p>Vous assurez ainsi que votre strat\u00e9gie SEO, y compris pour le GEO, reste coh\u00e9rente et performante m\u00eame dans le cadre de flux de travail complexes et automatis\u00e9s.<\/p>\n\n\n\n<div class=\"wp-block-rank-math-toc-block\" id=\"rank-math-toc\"><h2>Table des Mati\u00e8res<\/h2><nav><ul><li><a href=\"#plugin-word-press-rankmath-api\">Plugin WordPress Rankmath API Manager Extended<\/a><ul><li><a href=\"#3-activer-le-plugin\">Activer le plugin<\/a><\/li><\/ul><\/li><li><a href=\"#workflow-n-8-n\">Workflow n8n<\/a><\/li><li><a href=\"#version-bulk\">Version bulk<\/a><\/li><li><a href=\"#depannage\">D\u00e9pannage<\/a><ul><li><a href=\"#erreur-dauthentification\">Erreur d\u2019authentification<\/a><\/li><li><a href=\"#endpoint-non-accessible\">Endpoint non accessible<\/a><\/li><li><a href=\"#mise-a-jour-incorrecte\">Mise \u00e0 jour incorrecte<\/a><\/li><\/ul><\/li><\/ul><\/nav><\/div>\n\n\n\n<figure class=\"wp-block-embed is-type-video is-provider-youtube wp-block-embed-youtube wp-embed-aspect-4-3 wp-has-aspect-ratio\"><div class=\"wp-block-embed__wrapper\">\n<iframe title=\"Automatisez la mise \u00e0 jour des champs SEO Rank Math avec n8n \ud83d\ude80 | WordPress &amp; WooCommerce\" width=\"720\" height=\"540\" src=\"https:\/\/www.youtube.com\/embed\/KP7aIZAHrSc?feature=oembed\" frameborder=\"0\" allow=\"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share\" referrerpolicy=\"strict-origin-when-cross-origin\" allowfullscreen><\/iframe>\n<\/div><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"plugin-word-press-rankmath-api\"><strong>Plugin WordPress<\/strong> Rankmath API Manager Extended<\/h2>\n\n\n\n<p>Nous allons cr\u00e9er un plugin personnalis\u00e9 qui expose une nouvelle route REST permettant de mettre \u00e0 jour les m\u00e9tadonn\u00e9es SEO de Rank Math.<\/p>\n\n\n\n<p>Je suis parti de <a href=\"https:\/\/support.rankmath.com\/ticket\/rankmath-and-wordpress-api\/\" target=\"_blank\" rel=\"noopener\">cette version<\/a> que j&rsquo;ai \u00e9tendue gr\u00e2ce \u00e0 chatGPT et \u00e0 une discussion sur le channel de No Code Skills de J\u00e9r\u00e9my DE CAMPOS (mention  \u00e0 Recreabox \ud83d\ude0f).<\/p>\n\n\n\n<p>Cr\u00e9ez un fichier PHP (par exemple&nbsp;rank-math-api-manager-extended-v1.3.php), le compresser en zip et ensuite faire ajout nouveau plugin.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;?php\n\/**\n * Plugin Name: Rank Math API Manager Extended v1.3\n * Description: Manages the update of Rank Math metadata (SEO Title, SEO Description, Canonical URL) via the REST API for WordPress posts and WooCommerce products.\n * Version: 1.3\n * Author: Phil - https:\/\/inforeole.fr\n *\/\n\nif ( ! defined( 'ABSPATH' ) ) {\n    exit; \/\/ Exit if accessed directly.\n}\n\nclass Rank_Math_API_Manager_Extended {\n    public function __construct() {\n        add_action('rest_api_init', &#91;$this, 'register_meta_fields']);\n        add_action('rest_api_init', &#91;$this, 'register_api_routes']);\n    }\n\n    \/**\n     * Registers the Rank Math meta fields in the REST API for posts and products (if WooCommerce is active).\n     *\/\n    public function register_meta_fields() {\n        $meta_fields = &#91;\n            'rank_math_title'         =&gt; 'SEO Title',\n            'rank_math_description'   =&gt; 'SEO Description',\n            'rank_math_canonical_url' =&gt; 'Canonical URL'\n        ];\n\n        \/\/ Register meta for posts by default.\n        $post_types = &#91;'post'];\n\n        \/\/ If WooCommerce is active, add the 'product' post type.\n        if ( class_exists('WooCommerce') ) {\n            $post_types&#91;] = 'product';\n        }\n\n        foreach ( $post_types as $post_type ) {\n            foreach ( $meta_fields as $key =&gt; $description ) {\n                register_post_meta( $post_type, $key, &#91;\n                    'show_in_rest'   =&gt; true,\n                    'single'         =&gt; true,\n                    'type'           =&gt; 'string',\n                    'auth_callback'  =&gt; &#91;$this, 'check_update_permission'],\n                    'description'    =&gt; $description,\n                ] );\n            }\n        }\n    }\n\n    \/**\n     * Registers the REST API route to update Rank Math meta fields.\n     *\/\n    public function register_api_routes() {\n        register_rest_route( 'rank-math-api\/v1', '\/update-meta', &#91;\n            'methods'             =&gt; 'POST',\n            'callback'            =&gt; &#91;$this, 'update_rank_math_meta'],\n            'permission_callback' =&gt; &#91;$this, 'check_update_permission'],\n            'args'                =&gt; &#91;\n                'post_id' =&gt; &#91;\n                    'required'          =&gt; true,\n                    'validate_callback' =&gt; function( $param ) {\n                        return is_numeric( $param ) &amp;&amp; get_post( $param );\n                    }\n                ],\n                'rank_math_title' =&gt; &#91;\n                    'type'              =&gt; 'string',\n                    'sanitize_callback' =&gt; 'sanitize_text_field',\n                ],\n                'rank_math_description' =&gt; &#91;\n                    'type'              =&gt; 'string',\n                    'sanitize_callback' =&gt; 'sanitize_text_field',\n                ],\n                'rank_math_canonical_url' =&gt; &#91;\n                    'type'              =&gt; 'string',\n                    'sanitize_callback' =&gt; 'esc_url_raw',\n                ],\n            ],\n        ] );\n    }\n\n    \/**\n     * Updates the Rank Math meta fields via the REST API.\n     *\/\n    public function update_rank_math_meta( WP_REST_Request $request ) {\n        $post_id = $request-&gt;get_param( 'post_id' );\n        $fields  = &#91;'rank_math_title', 'rank_math_description', 'rank_math_canonical_url'];\n        $result  = &#91;];\n\n        foreach ( $fields as $field ) {\n            $value = $request-&gt;get_param( $field );\n            if ( $value !== null ) {\n                $update_result = update_post_meta( $post_id, $field, $value );\n                $result&#91; $field ] = $update_result ? 'updated' : 'failed';\n            }\n        }\n\n        if ( empty( $result ) ) {\n            return new WP_Error( 'no_update', 'No metadata was updated', &#91;'status' =&gt; 400] );\n        }\n\n        return new WP_REST_Response( $result, 200 );\n    }\n\n    \/**\n     * Checks if the current user has permission to update the meta fields.\n     *\/\n    public function check_update_permission() {\n        return current_user_can( 'edit_posts' );\n    }\n}\n\nnew Rank_Math_API_Manager_Extended();<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"3-activer-le-plugin\"><strong>Activer le plugin<\/strong><\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Rendez-vous dans le tableau de bord WordPress &gt; Extensions.<\/li>\n\n\n\n<li>Activez le plugin&nbsp;<strong>Rank Math API Manager Extended v1.3<\/strong>.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"workflow-n-8-n\">Workflow n8n<\/h2>\n\n\n\n<p>\u26a0\ufe0f si vous aviez d\u00e9j\u00e0 des credentials pour le WordPress que vous souhaitez mettre \u00e0 jour, pensez bien \u00e0 recr\u00e9er votre cl\u00e9 API pour qu&rsquo;elle prenne en compte la nouvel API<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" width=\"1024\" height=\"243\" src=\"https:\/\/inforeole.fr\/wp-content\/uploads\/CleanShot-2025-02-02-at-12.46.29@2x-1024x243.png\" alt=\"\" class=\"wp-image-9669\" title=\"- Inforeole\" srcset=\"https:\/\/inforeole.fr\/wp-content\/uploads\/CleanShot-2025-02-02-at-12.46.29@2x-1024x243.png 1024w, https:\/\/inforeole.fr\/wp-content\/uploads\/CleanShot-2025-02-02-at-12.46.29@2x-300x71.png 300w, https:\/\/inforeole.fr\/wp-content\/uploads\/CleanShot-2025-02-02-at-12.46.29@2x-768x182.png 768w, https:\/\/inforeole.fr\/wp-content\/uploads\/CleanShot-2025-02-02-at-12.46.29@2x.png 1288w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>HTTP request<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" width=\"339\" height=\"1024\" src=\"https:\/\/inforeole.fr\/wp-content\/uploads\/api-rankmath-wordpress-339x1024.png\" alt=\"\" class=\"wp-image-9670\" title=\"- Inforeole\" srcset=\"https:\/\/inforeole.fr\/wp-content\/uploads\/api-rankmath-wordpress-339x1024.png 339w, https:\/\/inforeole.fr\/wp-content\/uploads\/api-rankmath-wordpress-99x300.png 99w, https:\/\/inforeole.fr\/wp-content\/uploads\/api-rankmath-wordpress-768x2319.png 768w, https:\/\/inforeole.fr\/wp-content\/uploads\/api-rankmath-wordpress-509x1536.png 509w, https:\/\/inforeole.fr\/wp-content\/uploads\/api-rankmath-wordpress-678x2048.png 678w, https:\/\/inforeole.fr\/wp-content\/uploads\/api-rankmath-wordpress.png 1136w\" sizes=\"(max-width: 339px) 100vw, 339px\" \/><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"version-bulk\">Version bulk<\/h2>\n\n\n\n<p>J&rsquo;ai aussi une version \u00ab\u00a0bulk\u00a0\u00bb payante :  ce workflow sp\u00e9cifique est con\u00e7u pour optimiser en masse les titres et les descriptions des articles WordPress en utilisant Rank Math, un plugin SEO populaire pour WordPress.<\/p>\n\n\n\n<p>L&rsquo;api de WordPress ne proposant pas de moyen simple d&rsquo;obtenir la liste de tous les articles, j&rsquo;ai cr\u00e9\u00e9 une nouvelle API et cr\u00e9\u00e9 un Workflow de mise \u00e0 jour en masse :<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Le workflow commence par r\u00e9cup\u00e9rer une liste d&rsquo;articles depuis un site WordPress.<\/li>\n\n\n\n<li>Chaque article est analys\u00e9 (personnalisable) pour d\u00e9terminer les am\u00e9liorations potentielles des titres et descriptions en utilisant les fonctionnalit\u00e9s de Rank Math.<\/li>\n\n\n\n<li>Les titres et descriptions sont optimis\u00e9s en fonction des recommandations SEO de Rank Math.<\/li>\n\n\n\n<li>Les articles sont mis \u00e0 jour avec les nouveaux titres et descriptions optimis\u00e9s.<\/li>\n<\/ul>\n\n\n\n<p><a href=\"https:\/\/n8n.io\/workflows\/4646-rank-math-bulk-title-and-description-optimizer-for-wordpress\" target=\"_blank\" rel=\"noopener\">https:\/\/n8n.io\/workflows\/4646-rank-math-bulk-title-and-description-optimizer-for-wordpress<\/a><\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"depannage\"><strong>D\u00e9pannage<\/strong><\/h2>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"erreur-dauthentification\"><strong>Erreur d\u2019authentification<\/strong><\/h3>\n\n\n\n<p>Si vous obtenez une erreur de type \u00ab&nbsp;invalid_username&nbsp;\u00bb ou \u00ab&nbsp;Authorization failed&nbsp;\u00bb, v\u00e9rifiez que :<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Vous avez bien utilis\u00e9 un password applicatif.<\/li>\n\n\n\n<li>Vos identifiants (nom d\u2019utilisateur et mot de passe ou cl\u00e9s API) sont corrects.<\/li>\n\n\n\n<li>Le plugin de Basic Auth est install\u00e9 (si vous utilisez l\u2019authentification Basic).<\/li>\n\n\n\n<li>Vous avez recr\u00e9\u00e9 les credentials apr\u00e8s modification de l\u2019API.<\/li>\n\n\n\n<li>Qu&rsquo;un plugin de s\u00e9cu (ex. Worfence) bloque pas les password applicatifs.<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"endpoint-non-accessible\"><strong>Endpoint non accessible<\/strong><\/h3>\n\n\n\n<p>Si l\u2019URL&nbsp;https:\/\/your-domain.com\/wp-json\/rank-math-api\/v1\/update-meta&nbsp;ne r\u00e9pond pas :<\/p>\n\n\n\n<p>\u2022&nbsp;Assurez-vous que le plugin est activ\u00e9.<\/p>\n\n\n\n<p>\u2022&nbsp;V\u00e9rifiez l\u2019URL et testez-la avec cURL ou Postman.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"mise-a-jour-incorrecte\"><strong>Mise \u00e0 jour incorrecte<\/strong><\/h3>\n\n\n\n<p>Si les champs ne se mettent pas \u00e0 jour :<\/p>\n\n\n\n<p>\u2022&nbsp;V\u00e9rifiez que le&nbsp;post_id&nbsp;correspond \u00e0 un article ou produit existant.<\/p>\n\n\n\n<p>\u2022&nbsp;Assurez-vous que les param\u00e8tres sont correctement transmis et valid\u00e9s via l\u2019API REST.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Par d\u00e9faut, l&rsquo;API REST de WordPress n&rsquo;expose pas les champs&#8230;<\/p>\n","protected":false},"author":1,"featured_media":9669,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_kad_post_transparent":"","_kad_post_title":"","_kad_post_layout":"","_kad_post_sidebar_id":"","_kad_post_content_style":"","_kad_post_vertical_padding":"","_kad_post_feature":"","_kad_post_feature_position":"","_kad_post_header":false,"_kad_post_footer":false,"_kad_post_classname":"","_joinchat":[],"footnotes":""},"categories":[1],"tags":[],"class_list":["post-9661","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-blog"],"rank_math_title":"Mettre \u00e0 jour vos champs SEO Rank Math avec n8n : Guide API WordPress","rank_math_description":"D\u00e9couvrez comment automatiser la mise \u00e0 jour des champs SEO Rank Math via l'API WordPress avec n8n. Optimisez facilement vos donn\u00e9es SEO, lisez le guide complet.","rank_math_canonical_url":"","featured_image_src":"https:\/\/inforeole.fr\/wp-content\/uploads\/CleanShot-2025-02-02-at-12.46.29@2x.png","author_info":{"display_name":"Phil","author_link":"https:\/\/inforeole.fr\/author\/phil\/"},"_links":{"self":[{"href":"https:\/\/inforeole.fr\/wp-json\/wp\/v2\/posts\/9661","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/inforeole.fr\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/inforeole.fr\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/inforeole.fr\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/inforeole.fr\/wp-json\/wp\/v2\/comments?post=9661"}],"version-history":[{"count":12,"href":"https:\/\/inforeole.fr\/wp-json\/wp\/v2\/posts\/9661\/revisions"}],"predecessor-version":[{"id":10859,"href":"https:\/\/inforeole.fr\/wp-json\/wp\/v2\/posts\/9661\/revisions\/10859"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/inforeole.fr\/wp-json\/wp\/v2\/media\/9669"}],"wp:attachment":[{"href":"https:\/\/inforeole.fr\/wp-json\/wp\/v2\/media?parent=9661"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/inforeole.fr\/wp-json\/wp\/v2\/categories?post=9661"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/inforeole.fr\/wp-json\/wp\/v2\/tags?post=9661"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}