Search by

negusdev / seoinjector-php

NegusDev

Universal PHP library for SEO Injector - Works with Laravel, WordPress, Symfony, or any PHP project

Package info

github.com/NegusDev/seoinjector-php

Homepage

pkg:composer/negusdev/seoinjector-php

Statistics

Installs: 14

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

v0.5.0 2026-08-25 10:13 UTC

This package is auto-updated.

Last update: 2026-09-25 11:50:20 UTC


README

Latest Version Total Downloads License PHP Version

Universal PHP library for managing SEO metadata from a centralized dashboard. Works with Laravel, WordPress, Symfony, CodeIgniter, or any PHP project.

โœจ Features

  • ๐Ÿš€ Works with any PHP framework or vanilla PHP
  • ๐Ÿ“ฆ Zero dependencies
  • โšก Built-in file caching with intelligent expiration
  • ๐ŸŽจ WordPress integration included
  • ๐Ÿ”ง Laravel service provider included
  • ๐ŸŒ Symfony bundle ready
  • โœจ NEW ๐Ÿงฌ Dynamic SEO handling with context-aware metadata resolution
  • ๐Ÿ—ฃ๏ธ Multi-language support with auto-detection
  • ๐Ÿงช Fully tested with PHPUnit 10 compliance
  • ๐Ÿ“– Comprehensive documentation

๐Ÿ†• What's New in v0.5.0: Dynamic SEO Handling

SEO Injector now supports context-aware dynamic SEO resolution. Instead of managing individual SEO entries per product or article, you can define templates that automatically populate with your application's data.

Perfect for:

  • E-commerce product pages
  • Blog articles with dynamic metadata
  • User profiles or portfolio pages
  • Any content-driven application

Why Dynamic SEO?

Challenge Solution
Thousands of products, each needs unique SEO Define template, supply product context
SEO metadata gets stale Uses real-time product/article data
Managing meta tags per page is tedious Centralized templates + auto rendering
Social sharing needs different OG tags Dynamic OG generation from context

๐Ÿ“ฆ Installation

composer require negusdev/seoinjector-php

๐Ÿš€ Quick Start

Basic Static SEO (Vanilla PHP)

<?php
require 'vendor/autoload.php';
use SEOInjector\SEOInjector;

$seo = new SEOInjector('your_api_key');
?>
<!DOCTYPE html>
<html>
<head>
    <?php echo $seo->render(); ?>
</head>
<body>
    <!-- Your content -->
</body>
</html>

Dynamic SEO with Context (NEW!)

<?php
require 'vendor/autoload.php';
use SEOInjector\SEOInjector;

// Get your product/article data
$product = [
    'name' => 'iPhone 16 Pro',
    'description' => 'Latest flagship with A18 Pro chip',
    'image' => '[https://example.com/iphone16pro.jpg](https://example.com/iphone16pro.jpg)',
    'price' => 999,
    'rating' => 4.8,
];

$seo = new SEOInjector('your_api_key');

// Pass your data to SEO Injector
$seo
    ->setUrl('/products/iphone-16-pro')
    ->setContext(['product' => $product])
    ->setLanguage('en');

// Render dynamically resolved metadata
echo $seo->renderDynamic();
// Outputs: <title>iPhone 16 Pro - $999 | Your Store</title>
//          <meta name="description" content="...">
//          <meta property="og:image" content="...">
//          ...etc
?>

Get as Array Instead of HTML

$metadata =$seo->getDynamic();

echo $metadata['title'];           // "iPhone 16 Pro - $999 | Your Store"
echo $metadata['description'];     // "Latest flagship with A18 Pro chip"
echo $metadata['og_image'];        // "[https://example.com/iphone16pro.jpg](https://example.com/iphone16pro.jpg)"
echo $metadata['og_price_amount']; // "999"

Laravel Integration

// In your controller
Route::get('/products/{slug}', function($slug) {
    $product = Product::where('slug',$slug)->firstOrFail();

    $seo = app('seoinjector')
        ->setUrl(request()->path())
        ->setContext(['product' => $product->toArray()])
        ->setLanguage(app()->getLocale());

    return view('products.show', ['product' => $product, 'seo' =>$seo]);
});
<!-- In your blade template -->
<head>
    {!! $seo->renderDynamic() !!}
</head>

WordPress Integration

// In functions.php or plugin file
add_action('wp_head', function() {
    // For single posts/pages
    if (is_singular()) {
        $post = get_queried_object();

        $seo = new \SEOInjector\SEOInjector(
            get_option('seoinjector_api_key')
        );

        $seo->setContext([
            'post' => [
                'title' => $post->post_title,
                'excerpt' => get_the_excerpt($post),
                'image' => get_the_post_thumbnail_url($post),
            ]
        ]);

        echo $seo->renderDynamic();
    }
}, 1);

๐ŸŽฏ API Reference

Core Methods

setUrl(string $url): self

Set the URL/path to fetch SEO metadata for.

$seo->setUrl('/products/iphone-16-pro');

setContext(array $context): self (NEW!)

Pass application data for dynamic template resolution.

$seo->setContext([
    'product' => ['name' => '...', 'price' => '...'],
    'user' => ['name' => '...', 'avatar' => '...'],
]);

setLanguage(string $language): self

Explicitly set the language for metadata resolution (auto-detected from Accept-Language header if not set).

$seo->setLanguage('en'); // or 'fr', 'de', etc.

render(): string

Render static SEO metadata as HTML meta tags.

echo $seo->render();

renderDynamic(): string (NEW!)

Render context-aware dynamic SEO metadata as HTML.

echo $seo->setContext($data)->renderDynamic();

get(): ?array

Get static metadata as an associative array.

$metadata =$seo->get();
echo $metadata['title'];

getDynamic(): ?array (NEW!)

Get dynamically resolved metadata as an associative array.

$metadata = $seo->setContext($data)->getDynamic();
echo $metadata['og_image'];

clearCache(string $url): void

Clear cached metadata for a specific URL.

$seo->clearCache('/products/iphone-16-pro');

clearAllCache(): void

Clear all cached metadata.

$seo->clearAllCache();

โš™๏ธ Configuration

$seo = new SEOInjector('your_api_key', [
    'api_url' => '[https://api.seoinjector.com/api](https://api.seoinjector.com/api)', // Custom API endpoint
    'cache' => true,                                // Enable file caching
    'cache_duration' => 3600,                       // Cache TTL in seconds
    'debug' => false,                               // Enable debug logging
]);

๐Ÿงช Testing

composer test

๐Ÿ“– Full Documentation

๐Ÿ“ Changelog

See CHANGELOG.md for release notes and version history.

๐Ÿค Contributing

Contributions are welcome! Please see CONTRIBUTING.md for guidelines.

๐Ÿ“„ License

MIT License - see LICENSE file.

๐Ÿ”— Links