Creating vertical button layout for Telegram bot inline keyboard

I’m working on a Telegram bot using PHP and I’m having trouble with the button layout. Right now my inline keyboard shows all buttons in a horizontal row, which makes the text get cut off and display like “Text Bu…” instead of the full button text.

$buttonLayout = [
    'inline_keyboard' => [['text' => $locationName, 'callback_data' => $locationId]],
];
$keyboardMarkup = json_encode($buttonLayout, true);
$messageData = [
    'chat_id' => $userId,
    'reply_markup' => $keyboardMarkup,
    'text' => 'Select a location from the list below to view its map.',
    'disable_notification' => true
];

The current setup creates buttons that are arranged side by side, but I need them to be stacked vertically so users can see the complete button text. How do I modify the keyboard structure to create a vertical column of buttons instead of a horizontal row? I want each button to appear on its own line like in the official Telegram documentation examples.

Your array nesting’s off. Telegram treats each sub-array as a separate row, so for vertical buttons you need one button per sub-array. Try [[$button1], [$button2]] instead of [[$button1, $button2]] - fixed the same issue on my weather bot.

Your inline keyboard array is structured incorrectly. You’re placing all buttons in a single row, which enforces a horizontal layout and truncates the text. Instead, wrap each button in its own array:

$buttonLayout = [
    'inline_keyboard' => [
        [['text' => $locationName1, 'callback_data' => $locationId1]],
        [['text' => $locationName2, 'callback_data' => $locationId2]],
        [['text' => $locationName3, 'callback_data' => $locationId3]]
    ]
];

Having each button in its own nested array creates a separate row, ensuring every button appears on its own line without being truncated. I encountered the same issue with a restaurant menu bot, where location names were being cut off until I corrected the structure.

Your inline_keyboard array structure is the issue. Each sub-array creates a row of buttons, so when you put multiple buttons in one sub-array, they align horizontally. To achieve vertical buttons, ensure that each button is placed in its own sub-array. Instead of using [[‘button1’, ‘button2’]], you should use [[‘button1’], [‘button2’]]. This will make each button appear on its own line, preventing the text from being cut off. I’ve faced this error when working on my first Telegram bot and spent too much time trying to resolve it.