Pillar B — Build guides
Published 2026-06-11 · Updated 2026-06-19 · By Avinash Chandan, Founder, Navamsha
Add a Panchang Widget to WordPress Using Navamsha API
WordPress sites can show daily Panchang without running ephemeris locally. Store your Navamsha API key in wp-config.php, fetch Panchang server-side with wp_remote_get, cache the JSON with transients, and render a shortcode block for tithi and nakshatra.
Secure key storage
Add define('NAVAMSHA_API_KEY', 'your_key'); to wp-config.php — never in theme files committed to git.
PHP — cached Panchang shortcode
function navamsha_panchang_shortcode() {
$cache_key = 'navamsha_panchang_' . date('Y-m-d');
$cached = get_transient($cache_key);
if ($cached) return $cached;
$url = add_query_arg([
'date' => date('Y-m-d'),
'latitude' => 19.0760,
'longitude' => 72.8777,
], 'https://api.navamsha.in/api/v1/panchang/daily');
$response = wp_remote_get($url, [
'headers' => ['X-API-Key' => NAVAMSHA_API_KEY],
'timeout' => 15,
]);
if (is_wp_error($response)) return '<p>Panchang unavailable</p>';
$body = json_decode(wp_remote_retrieve_body($response), true);
$html = '<div class="navamsha-panchang">'
. esc_html($body['data']['tithi']['name'] ?? 'Tithi')
. ' · ' . esc_html($body['data']['nakshatra']['name'] ?? 'Nakshatra')
. '</div>';
set_transient($cache_key, $html, DAY_IN_SECONDS);
return $html;
}
add_shortcode('navamsha_panchang', 'navamsha_panchang_shortcode');Site owner checklist
- Set latitude/longitude for your temple or city — or add a settings page for admins.
- One transient cache per day keeps you well within 10,000 free calls/month.
- Link to www.navamsha.in/getting-started for API key signup.
FAQ
Do I need a custom plugin?
A minimal mu-plugin or theme functions.php snippet works. Package as a plugin if you distribute to multiple sites.
Is wp_remote_get allowed on shared hosting?
Most hosts allow outbound HTTPS. If blocked, proxy through a small Cloudflare Worker with your API key.