// ================================ // Custom REST API endpoint for updating Rank Math SEO fields via n8n // ================================ add_action('rest_api_init', function () { register_rest_route('rankmath/v1', '/update-meta', array( 'methods' => 'POST', 'callback' => 'update_rankmath_meta_from_n8n', 'permission_callback' => '__return_true', // Secured by secret key )); }); function update_rankmath_meta_from_n8n(WP_REST_Request $request) { $secret_key = 'Mx8P@9qk#12Zr'; // Change to your own strong key // Security check if ($request->get_header('x-secret-key') !== $secret_key) { return new WP_REST_Response(array('error' => 'Unauthorized'), 401); } $post_id = intval($request->get_param('post_id')); $title = sanitize_text_field($request->get_param('title')); $description = sanitize_text_field($request->get_param('description')); $keywords = sanitize_text_field($request->get_param('keywords')); if (!$post_id) { return new WP_REST_Response(array('error' => 'Post ID required'), 400); } // Update Rank Math fields if (!empty($title)) { update_post_meta($post_id, 'rank_math_title', $title); } if (!empty($description)) { update_post_meta($post_id, 'rank_math_description', $description); } if (!empty($keywords)) { update_post_meta($post_id, 'rank_math_focus_keyword', $keywords); } return new WP_REST_Response(array( 'success' => true, 'post_id' => $post_id, 'title' => $title, 'description' => $description, 'keywords' => $keywords ), 200); } Link Building Services - 7 Link Building Services That Actually Work 2024 | Link Building Services | 10 link-building services to scale your SEO efforts| Top-rated Link Building Services For Seo Boost| 8 Link Building Services Actually Worth Your Money | The 9 Best Link Building Services for 2024
Home Web Technology Link Building Services

Menu

Subscribe to EchoPx

Subscribe my Newsletter for new blog posts, tips & new photos. Let's stay updated!

Copyright © 2024 | Website Developed by EchoPx.com

error: Content is protected !!