Skip to main content
Glama

wpnav_gutenberg_move_block

Move Gutenberg blocks within WordPress posts to reorganize content structure or reposition nested elements for better layout management.

Instructions

Move a Gutenberg block from one path to another. Useful for reordering blocks or moving nested blocks.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
post_idYesPost ID to modify
from_pathYesSource path (block to move)
to_pathYesDestination path (where to move block)

Implementation Reference

  • Handler function that validates input parameters (post_id, from_path, to_path) and performs the block move by calling the WordPress REST API endpoint '/wpnav/v1/gutenberg/blocks/move'.
    handler: async (args, context) => { validateRequired(args, ['post_id', 'from_path', 'to_path']); const id = validateId(args.post_id, 'Post'); if (!validatePath(args.from_path)) { return { content: [{ type: 'text', text: context.clampText(JSON.stringify({ error: 'invalid_from_path', message: 'from_path must be non-empty array of non-negative integers', }, null, 2)), }], isError: true, }; } if (!validatePath(args.to_path)) { return { content: [{ type: 'text', text: context.clampText(JSON.stringify({ error: 'invalid_to_path', message: 'to_path must be non-empty array of non-negative integers', }, null, 2)), }], isError: true, }; } // Call REST API const result = await context.wpRequest('/wpnav/v1/gutenberg/blocks/move', { method: 'POST', body: JSON.stringify({ post_id: id, from_path: args.from_path, to_path: args.to_path, }), }); if (!result.success) { return { content: [{ type: 'text', text: context.clampText(JSON.stringify({ error: result.error }, null, 2)), }], isError: true, }; } return { content: [{ type: 'text', text: context.clampText(JSON.stringify({ success: true, post_id: id, from_path: args.from_path, to_path: args.to_path, message: 'Block moved successfully', }, null, 2)), }], }; },
  • Input schema defining the required parameters for the tool: post_id (number), from_path (array of numbers), to_path (array of numbers).
    inputSchema: { type: 'object', properties: { post_id: { type: 'number', description: 'Post ID to modify', }, from_path: { type: 'array', items: { type: 'number' }, description: 'Source path (block to move)', }, to_path: { type: 'array', items: { type: 'number' }, description: 'Destination path (where to move block)', }, }, required: ['post_id', 'from_path', 'to_path'], },
  • Full registration of the wpnav_gutenberg_move_block tool using toolRegistry.register, including definition (name, description, schema), handler, and category.
    toolRegistry.register({ definition: { name: 'wpnav_gutenberg_move_block', description: 'Move a Gutenberg block from one path to another. Useful for reordering blocks or moving nested blocks.', inputSchema: { type: 'object', properties: { post_id: { type: 'number', description: 'Post ID to modify', }, from_path: { type: 'array', items: { type: 'number' }, description: 'Source path (block to move)', }, to_path: { type: 'array', items: { type: 'number' }, description: 'Destination path (where to move block)', }, }, required: ['post_id', 'from_path', 'to_path'], }, }, handler: async (args, context) => { validateRequired(args, ['post_id', 'from_path', 'to_path']); const id = validateId(args.post_id, 'Post'); if (!validatePath(args.from_path)) { return { content: [{ type: 'text', text: context.clampText(JSON.stringify({ error: 'invalid_from_path', message: 'from_path must be non-empty array of non-negative integers', }, null, 2)), }], isError: true, }; } if (!validatePath(args.to_path)) { return { content: [{ type: 'text', text: context.clampText(JSON.stringify({ error: 'invalid_to_path', message: 'to_path must be non-empty array of non-negative integers', }, null, 2)), }], isError: true, }; } // Call REST API const result = await context.wpRequest('/wpnav/v1/gutenberg/blocks/move', { method: 'POST', body: JSON.stringify({ post_id: id, from_path: args.from_path, to_path: args.to_path, }), }); if (!result.success) { return { content: [{ type: 'text', text: context.clampText(JSON.stringify({ error: result.error }, null, 2)), }], isError: true, }; } return { content: [{ type: 'text', text: context.clampText(JSON.stringify({ success: true, post_id: id, from_path: args.from_path, to_path: args.to_path, message: 'Block moved successfully', }, null, 2)), }], }; }, category: ToolCategory.CONTENT, });
  • validatePath helper function used to validate from_path and to_path arrays in the handler.
    /** * Validate path array * * Ensures path is a valid array of non-negative integers. * * @param path Path array to validate * @returns True if valid, false otherwise */ export function validatePath(path: number[]): boolean { if (!Array.isArray(path)) { return false; } if (path.length === 0) { return false; } return path.every(n => Number.isInteger(n) && n >= 0); }

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/littlebearapps/wp-navigator-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server