Build a Voice-Enabled Website with ElevenLabs and WordPress
Why Voice‑Enabled Sites Are the Next Big Thing If you’ve ever browsed a site and thought, “I wish this could read the article out loud,” you’re not alone. Voice‑first experiences are exploding—from podcasts to smart‑sp
Why Voice‑Enabled Sites Are the Next Big Thing
If you’ve ever browsed a site and thought, “I wish this could read the article out loud,” you’re not alone. Voice‑first experiences are exploding—from podcasts to smart‑speaker apps—and adding text‑to‑speech (TTS) to a WordPress site is now a few lines of code away.
In this tutorial we’ll:
- Generate natural‑sounding audio with ElevenLabs – the industry‑leading voice cloning platform.
- Hook the audio into a WordPress page so visitors can click a “Play” button and listen instantly.
- Deploy the whole thing on a reliable, affordable host – we’ll use Bluehost for its one‑click WordPress setup and cheap plans.
By the end you’ll have a fully functional voice‑enabled page that you can extend to blog posts, product descriptions, or even a full‑blown audio‑blog.
Getting Started: What You’ll Need
| Item | Why It’s Needed |
|---|---|
| ElevenLabs account | Provides the TTS API and voice cloning capabilities. Sign up here: ElevenLabs |
| WordPress site | The content management system we’ll embed the audio player into. |
| Bluehost hosting | Offers an easy, affordable way to spin up a WordPress site with just a few clicks. Grab a plan here: Bluehost |
| API key | Required to authenticate calls to ElevenLabs. |
| Basic PHP/JS knowledge | To add the shortcode and enqueue scripts. |
If you already have a WordPress site, skip the hosting step. Otherwise, head over to Bluehost, pick a plan, and launch WordPress with their one‑click installer. It’s fast, cheap, and you’ll have a live domain in minutes.
Step 1 – Create an ElevenLabs Voice
- Log into your ElevenLabs dashboard via the affiliate link above.
- Click “Create Voice” and follow the wizard – you can either upload a few seconds of your own voice or pick one of the pre‑made premium voices.
- Once the voice is ready, copy the API Key from the Settings → API page. Keep it safe; we’ll need it in the next step.
Tip: The free tier gives you 10 k characters per month, which is plenty for testing.
Step 2 – Add a Simple TTS Endpoint (PHP)
We’ll expose a tiny endpoint in WordPress that receives a piece of text, forwards it to ElevenLabs, and returns the generated audio URL.
Create a file called tts-endpoint.php inside your theme folder (e.g., wp-content/themes/your-theme/tts-endpoint.php):
<?php
// tts-endpoint.php – WordPress-friendly TTS proxy
if ( ! defined( 'ABSPATH' ) ) {
exit; // Prevent direct access
}
// Expect a POST request with `text` and optional `voice_id`
$input = json_decode( file_get_contents('php://input'), true );
$text = $input['text'] ?? '';
$voice = $input['voice_id'] ?? 'EXAVITQu4vr4xnG8'; // default voice ID
if ( empty( $text ) ) {
wp_send_json_error( 'No text provided' );
exit;
}
// ElevenLabs API call
$apiKey = 'YOUR_ELEVENLABS_API_KEY'; // <-- replace with your key
$endpoint = "https://api.elevenlabs.io/v1/text-to-speech/{$voice}";
$payload = [
'text' => $text,
'voice_settings' => [
'stability' => 0.75,
'similarity_boost' => 0.85
]
];
$ch = curl_init( $endpoint );
curl_setopt_array( $ch, [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => [
"Content-Type: application/json",
"xi-api-key: {$apiKey}"
],
CURLOPT_POST => true,
CURLOPT_POSTFIELDS => json_encode( $payload )
]);
$response = curl_exec( $ch );
$httpCode = curl_getinfo( $ch, CURLINFO_HTTP_CODE );
curl_close( $ch );
if ( $httpCode !== 200 ) {
wp_send_json_error( 'ElevenLabs error: ' . $response );
exit;
}
// ElevenLabs returns raw audio; we’ll store it temporarily
$audioFile = wp_upload_dir()['basedir'] . '/' . uniqid() . '.mp3';
file_put_contents( $audioFile, $response );
$audioUrl = wp_upload_dir()['baseurl'] . '/' . basename( $audioFile );
wp_send_json_success( [ 'audio_url' => $audioUrl ] );
?>
Security note: In a production setup you’d want to add nonce verification and rate limiting. This example keeps things simple for learning purposes.
Now expose the endpoint via WordPress rewrite rules. Add the following to your theme’s functions.php:
function add_tts_endpoint() {
add_rewrite_rule( '^tts-endpoint/?$', 'index.php?tts_endpoint=1', 'top' );
}
add_action( 'init', 'add_tts_endpoint' );
function tts_query_vars( $vars ) {
$vars[] = 'tts_endpoint';
return $vars;
}
add_filter( 'query_vars', 'tts_query_vars' );
function tts_template_redirect() {
if ( get_query_var( 'tts_endpoint' ) ) {
require_once get_template_directory() . '/tts-endpoint.php';
exit;
}
}
add_action( 'template_redirect', 'tts_template_redirect' );
Visit Settings → Permalinks and click Save Changes to flush rewrite rules. Your endpoint is now reachable at https://yourdomain.com/tts-endpoint.
Step 3 – Front‑End: A Play Button Shortcode
Let’s give content creators a simple shortcode they can drop anywhere: [voice_reader]Your text here[/voice_reader].
Add this to functions.php:
function voice_reader_shortcode( $atts, $content = '' ) {
$content = trim( $content );
if ( empty( $content ) ) {
return '';
}
// Unique IDs to avoid collisions
$uid = uniqid('vr_');
// Enqueue a tiny JS bundle (we’ll add it later)
wp_enqueue_script( 'voice-reader-js', get_template_directory_uri() . '/js/voice-reader.js', [], null, true );
// Output the button and an empty audio tag
return "
<div class='voice-reader' id='{$uid}'>
<button class='vr-play' data-text='" . esc_attr( $content ) . "'>🔊 Listen</button>
<audio class='vr-audio' controls style='display:none;'></audio>
</div>
";
}
add_shortcode( 'voice_reader', 'voice_reader_shortcode' );
Create js/voice-reader.js inside your theme:
document.addEventListener('click', function(e) {
if (!e.target.matches('.vr-play')) return;
const btn = e.target;
const container = btn.closest('.voice-reader');
const audioEl = container.querySelector('.vr-audio');
const text = btn.dataset.text;
btn.disabled = true;
btn.textContent = '⏳ Generating...';
fetch('/tts-endpoint', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ text: text })
})
.then(r => r.json())
.then(data => {
if (data.success) {
audioEl.src = data.data.audio_url;
audioEl.style.display = 'block';
audioEl.play();
} else {
alert('Error: ' + data.data);
}
})
.catch(err => alert('Fetch error: ' + err))
.finally(() => {
btn.disabled = false;
btn.textContent = '🔊 Listen';
});
});
Now you can write a post like:
[voice_reader]Welcome to our new product launch! Stay tuned for more updates.[/voice_reader]
When a visitor clicks Listen, the text is sent to your PHP proxy, ElevenLabs turns it into speech, and the audio plays right in the browser.
Step 4 – Deploy on Bluehost
If you chose Bluehost for hosting, you already have a one‑click WordPress install. Here’s a quick checklist to get your voice AI live:
- Log into the Bluehost dashboard → My Sites → Create Site.
- Pick a domain (or subdomain) and let Bluehost spin up WordPress.
- Use the built‑in File Manager or an FTP client (e.g., FileZilla) to upload the
tts-endpoint.php,functions.phpchanges, and thejs/voice-reader.jsfile into your theme folder. - Visit Settings → Permalinks and click Save to refresh rewrite rules.
- Test a post with the
[voice_reader]shortcode – you should hear the audio instantly.
Bluehost’s managed environment handles PHP, SSL, and automatic backups, so you can focus on building cool voice experiences instead of server maintenance.
Bonus: Using cURL Directly (Optional)
If you prefer to bypass the WordPress proxy and call ElevenLabs straight from a script, here’s a quick cURL example:
curl -X POST "https://api.elevenlabs.io/v1/text-to-speech/EXAVITQu4vr4xnG8" \
-H "Content-Type: application/json" \
-H "xi-api-key: YOUR_ELEVENLABS_API_KEY" \
-d '{
"text": "Hello, WordPress world! This is ElevenLabs speaking.",
"voice_settings": { "stability": 0.75, "similarity_boost": 0.85 }
}' --output hello.mp3
The generated hello.mp3 can be uploaded to the Media Library and embedded like any other audio file.
What’s Next?
- Voice cloning: Record a few minutes of your own voice, upload it to ElevenLabs, and let the site read everything in your voice.
-
Dynamic post reading: Hook into
the_contentfilter to automatically add a listener to every article. -
Multilingual support: ElevenLabs supports several languages – just pass the appropriate
languageparameter.
The possibilities are endless, and the core plumbing is already in place.
Ready to Give Your Site a Voice?
If you’re excited to turn static text into engaging audio, start by signing up for ElevenLabs here: https://try.elevenlabs.io/kr07zfuqn1bp.
Then, spin up a WordPress site on the hassle‑free, budget‑friendly platform that powers millions of blogs: https://bluehost.sjv.io/5k0d52.
Happy coding, and enjoy hearing your content come to life!
Originally published by Dev.to AI. Aggregated on AIWithGhost for educational purposes — full credit and traffic to the original publisher.