Add Bible verses to WordPress with a shortcode

This guide adds a [bible_verse] shortcode to a WordPress site, so editors can drop a passage into any post or page. The verse is fetched on your server and saved for a day, so pages stay fast.

Uses a secret key (bva_sk_…), because the code runs on a server.

1. Save your key in wp-config.php

Create a secret key (bva_sk_) at bibleverse-api.com and add this line to wp-config.php, above “That's all, stop editing!”.

wp-config.php
define( 'BIBLE_VERSE_API_KEY', 'bva_sk_…' );

2. Add the plugin

Save this as wp-content/plugins/bible-verse/bible-verse.php, then turn it on under Plugins.

bible-verse.php
<?php
/**
 * Plugin Name: Bible Verse shortcode
 * Description: [bible_verse ref="John 3:16"] shows a passage from Bible Verse API.
 */

add_shortcode( 'bible_verse', function ( $atts ) {
	$atts  = shortcode_atts( array( 'ref' => 'John 3:16', 'bible' => 'kjv' ), $atts );
	$cache = 'bva_' . md5( $atts['bible'] . '|' . $atts['ref'] );

	$text = get_transient( $cache );
	if ( false === $text ) {
		$url = add_query_arg(
			array( 'ref' => rawurlencode( $atts['ref'] ), 'format' => 'text' ),
			'https://api.bibleverse-api.com/v1/bibles/' . rawurlencode( $atts['bible'] ) . '/passages'
		);
		$res = wp_remote_get( $url, array(
			'headers' => array( 'Authorization' => 'Bearer ' . BIBLE_VERSE_API_KEY ),
			'timeout' => 10,
		) );
		if ( is_wp_error( $res ) || 200 !== wp_remote_retrieve_response_code( $res ) ) {
			return '';
		}
		$text = wp_remote_retrieve_body( $res );
		set_transient( $cache, $text, DAY_IN_SECONDS );
	}

	return '<blockquote class="bible-verse">' . nl2br( esc_html( $text ) ) . '</blockquote>';
} );

3. Use the shortcode

In any post or page, add [bible_verse ref="Psalm 23:1-3"]. Choose a translation with bible, for example [bible_verse ref="John 3:16" bible="web"].

The passage includes its attribution line, so the licence requirement is covered.

Ready to try it?

The Free plan gives you 5,000 requests and 2,000 verses a day, with no card.

Get a free API keyRead the API docs