Install
This is the repository archive. It installs, but the folder name will carry the branch suffix and updates will not flow.
Install straight from GitHub with WP-CLI:
wp plugin install https://github.com/cjbodullo/name-generator-plugin/archive/refs/heads/master.zipNo built-in updater. New versions won't appear under Dashboard → Updates. Install new releases yourself, or let Git Updater track the repository.
WordPress plugin that renders an AI-powered baby name generator via shortcode.
Text domain: baby-name-generator
Version: 1.0.0 (BNG_VERSION in the main plugin file).
Requirements
- WordPress 5.x or newer.
- PHP 7.4+ (uses
wp_remote_post,wp_send_json_*, anonymous functions). - A Google Gemini API key — create one at https://aistudio.google.com/app/apikey.
Installation
- Copy the folder
name-generator-pluginintowp-content/plugins/. - In Plugins, activate Baby Name Generator.
- Open Settings → Baby Name Generator and paste your Gemini API key. Optionally change the model (default
gemini-2.0-flash). - Add the shortcode
[baby_name_generator]to any page or post.
Shortcode
[baby_name_generator]
Attributes (all optional)
| Attribute | Default | Purpose |
|---|---|---|
title |
FIND THE PERFECT BABY NAME FOR YOUR LITTLE ONE |
Heading shown above the form. |
intro_top |
Lead copy from the standalone tool | First (bold) intro paragraph. Pass empty string to hide. |
intro_bottom |
Long description from the standalone tool | Second intro paragraph. Pass empty string to hide. |
count |
8 |
Names per initial Generate (1–20). |
more_count |
5 |
Names per Show More click (1–20). |
Example
[baby_name_generator title="Pick a Name" intro_top="" intro_bottom="" count="6" more_count="4"]
Features
- Filters: gender (All / For Him / For Her / Neutral), one or more first letters, origin, style, meaning, # syllables.
- Free text "Search by name" for "names similar to…".
- Generate triggers a JSON-mode Gemini call (
generateContentwithresponseMimeType: application/json). - Show more keeps the original criteria and excludes already-shown names so results stay unique.
- Inline expanding card per name with origin, meaning, popularity, and a 2–3 sentence description.
- Heart / plus icons toggle locally (no persistence yet).
Architecture
| Piece | Path |
|---|---|
| Plugin entry | name-generator-plugin.php |
| Shortcode markup | bng_render_shortcode() |
| AJAX endpoint | wp_ajax_bng_generate_names (and _nopriv for visitors) — bng_handle_generate_names() |
| Gemini call | bng_call_gemini_api() using wp_remote_post |
| Front-end JS | assets/js/baby-name-generator.js |
| Styles | assets/css/baby-name-generator.css (all selectors prefixed bng-) |
| Admin settings | Settings → Baby Name Generator (options-general.php?page=baby-name-generator) |
The API key is stored in the wp_options row keyed by bng_settings and is never exposed to the browser. The browser only sees a per-page nonce.
Security notes
- Public AJAX is nonce-protected (
bng_generate_names). - All form fields are validated against an allow-list before they reach the model.
- Returned names are sanitised with
sanitize_text_field/wp_kses_postbefore being sent back to the browser, then injected as text (not HTML) on the client to keep the DOM safe even if the model misbehaves. - Settings page requires
manage_options.
Customising
- CSS is fully scoped under
.bng-shell; override any rule from your theme by targeting.bng-shell .bng-…. - Change the default model or use a different one (e.g.
gemini-1.5-pro) from the settings page. - The prompt is built in
bng_build_prompt()— tweak it there if you want different output guidance.