YuktaiDocs v5.3.12

PHP (Composer)

YuktAI for PHP

The yuktishaalaa/yuktai package adds YuktAI to any PHP page in one line: plain PHP, Laravel, WordPress or Symfony. You get the ♿ accessibility widget, the 🛠 page tools and everything in window.yuktai. YuktAI still runs in the visitor's browser. The package only writes the right script tags for you.

1. Install

Terminal
composer require yuktishaalaa/yuktai

On Packagist: packagist.org/packages/yuktishaalaa/yuktai (opens in a new tab)

2. Plain PHP

index.php (before </body>)
<?= \Yuktai\Yuktai::script(['position' => 'right', 'showPageTools' => true]) ?>

Composer's vendor/autoload.php must be loaded once, as in any Composer project.

3. Laravel

resources/views/layouts/app.blade.php (before </body>)
{!! \Yuktai\Yuktai::script(['showPageTools' => true]) !!}

Use {!! !!}, not {{ }}: the result is HTML and must not be escaped again.

4. WordPress

functions.php (your theme)
add_action('wp_footer', function () {
    echo \Yuktai\Yuktai::script(['position' => 'right', 'showPageTools' => true]);
});

WordPress loads wp_footer just before </body> on every page.

Options

Keys of the array passed to Yuktai::script()
OptionWhat it does
versionYuktAI release to load. The package pins a tested release; "latest" follows new releases.
position"left" or "right"
primaryColorButton colour, for example "#0a4a85"
titleTitle of the settings dialog (Telugu works)
showPageToolsAdds the 🛠 page tools button
defaultTabcopilot, qa, forms, design, ask or voice
voiceLangSpeech language, for example "te-IN"
autoFix, showSkipLinksAccessibility engine options
extraAny other YUKTAI_CONFIG key, as ['key' => value]
cdn"jsdelivr" (default) or "unpkg"
defertrue by default
nonceFor pages with a Content Security Policy

Safe by design

Safe JSON

Options are written with JSON_HEX_TAG and JSON_HEX_AMP, so a value like </script> can't break out of the tag.

Typos caught

A wrong value or an unknown option name (like showPagetools) throws InvalidArgumentException instead of being ignored.

CSP ready

Pass 'nonce' => $nonce and both script tags get it. Add cdn.jsdelivr.net to script-src, and 'wasm-unsafe-eval' for the Rust engines.

Tested

PHPUnit tests run on PHP 8.1, 8.2, 8.3 and 8.4 for every push.