WordPress AI integration without the hardcoded mess

I recently had a client come to me with a common enough problem. They wanted to build some real AI capabilities into their WordPress site: dynamic content generation, smart product descriptions for WooCommerce, personalized user experiences, that kind of thing.

The issue wasn’t the ambition, it was the execution. They’d brought on a freelancer who, bless his heart, had gone down the rabbit hole of trying to custom-build a WordPress AI integration. That meant direct calls to one AI provider’s API, hardcoded keys in custom settings, and a pile of spaghetti code every time they wanted to test a different model. The client was stuck, unable to switch providers or scale their AI features. Total mess.

My first thought was to grab a generic PHP AI client library and start plugging it in. That would have gotten a connection working. But you are still on the hook for storing API keys securely in WordPress, working around the WordPress HTTP API quirks, and abstracting away the different provider interfaces. It turns into a security and maintenance problem the moment you need more than one AI service, or you just want to swap models.

Simplify WordPress AI integration with the client SDK

That is where the WordPress AI Client SDK comes in. It was built to solve exactly this. It gives plugins and themes a WordPress-native way to talk to multiple generative AI providers through one consistent API. It is more than a thin wrapper: it follows WordPress conventions, uses the WP HTTP API, and hooks into WP Admin for credential management. You can read more about it on the WordPress AI blog.

To add this to your plugin or theme, start by pulling it in with Composer:

composer require wordpress/wp-ai-client

Then you initialize the client so everything hooks into WordPress correctly.

<?php
namespace Bbioon\AI_Integration;

use WordPress\AI_Client\AI_Client;

/**
 * Initializes the AI Client SDK.
 *
 * @return void
 */
function bbioon_ai_init() {
    AI_Client::init();
}
add_action( 'init', 'Bbioon\AI_Integration\bbioon_ai_init' );

Once that is done, your clients (or you) go to Settings → AI Credentials in WP Admin and enter their API keys. From there the SDK stores those credentials securely and wires them in automatically whenever you make a prompt request. No more editing wp-config.php or building custom options panels just for API keys.

Now for the actual AI call. Here is how you would generate text:

<?php
namespace Bbioon\AI_Integration;

use WordPress\AI_Client\AI_Client;

/**
 * Generates a summary using the AI Client SDK.
 *
 * @param string $text_to_summarize The text to summarize.
 * @return string The generated summary.
 */
function bbioon_generate_summary( string $text_to_summarize ): string {
    $summary = AI_Client::prompt( 'Summarize the following text: ' . $text_to_summarize )
        ->using_temperature( 0.1 )
        ->generate_text();

    return $summary;
}

// Example usage:
// $article_content = 'The history of the printing press is a fascinating journey...';
// $generated_summary = bbioon_generate_summary( $article_content );
// echo '<!-- wp:paragraph --><p>' . esc_html( $generated_summary ) . '</p><!-- /wp:paragraph -->';

The part I like is the automatic model selection. If you do not specify a model, the SDK picks one based on the configured providers and the capabilities you need. That keeps your features working as long as any supported provider is set up, not one specific provider. If you want more control, you can pass a preference list, or force a specific model as long as you add logic to check that it is available first.

Why this approach matters

The takeaway is standardization. The WordPress AI Client SDK is part of the larger AI Building Blocks for WordPress, not a one-off library. As AI capabilities change, your WordPress code stays portable, secure, and easier to maintain. You are not locking yourself into a single provider or a bespoke setup that breaks with the next API change. You are building on WordPress-native infrastructure.

This stuff gets complicated fast. If you’re tired of debugging someone else’s mess and just want your site to work, drop my team a line. We’ve probably seen it before.

author avatar
Ahmad Wael
I'm a WordPress and WooCommerce developer with 15+ years of experience building custom e-commerce solutions and plugins. I specialize in PHP development, following WordPress coding standards to deliver clean, maintainable code. Currently, I'm exploring AI and e-commerce by building multi-agent systems and SaaS products that integrate technologies like Google Gemini API with WordPress platforms, approaching every project with a commitment to performance, security, and exceptional user experience.