PHPackages                             jacky525/seo - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. jacky525/seo

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

jacky525/seo
============

Simple PHP library to help developers 🍻 do better on-page SEO optimization

v1.21(6y ago)02.2kMITPHPPHP &gt;=5.4

Since Mar 2Pushed 6y agoCompare

[ Source](https://github.com/jacky525/seo)[ Packagist](https://packagist.org/packages/jacky525/seo)[ RSS](/packages/jacky525-seo/feed)WikiDiscussions master Synced 2mo ago

READMEChangelogDependencies (1)Versions (23)Used By (0)

PHP SEO [![Build Status](https://camo.githubusercontent.com/f3e88f5c5394fdc018021aa52bd5549b456a377da7c96b3b3bd142b98e3a2334/68747470733a2f2f7472617669732d63692e6f72672f6a61636b793532352f73656f2e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/jacky525/seo)
===========================================================================================================================================================================================================================================================================

[](#php-seo-)

Simple PHP library to help developers 🍻 do better on-page SEO optimization

### PHP SEO features:

[](#php-seo-features)

- [\[👷\]](#-generate-schemaorg) **Generate schema.org ld+json**
- [\[🛀\]](#-meta-tags) **Generate meta tags with twitter and open graph support**
- [\[🗺\]](#-sitemaps) **Generate sitemaps xml and indexes (supports: 🖺 news, 🖼 images, 📽 videos)**
- [\[📤\]](#-send-sitemaps-to-search-engines) **Submit new sitempas to 🌐 search engines**
- [\[🙈\]](#see_composer_json) **No dependencies**
- [\[🖧\]](#todos) **&amp;&amp; more coming soon...**

Installation:
-------------

[](#installation)

```
composer require melbahja/seo
```

Usage:
------

[](#usage)

Check this simple examples. (of course the composer autoload.php file is required)

#### 👷 Generate schema.org

[](#-generate-schemaorg)

```
use Melbahja\Seo\Factory;

$schema = Factory::schema('organization')
            ->url('https://example.com')
            ->logo('https://example.com/logo.png')
                ->contactPoint
                    ->telephone('+1-000-555-1212')
                    ->contactType('customer service');

echo $schema;
```

**Results:** (formatted)

```

{
   "@context":"https:\/\/schema.org",
   "@type":"Organization",
   "url":"https:\/\/example.com",
   "logo":"https:\/\/example.com\/logo.png",
   "contactPoint":{
      "@type":"ContactPoint",
      "telephone":"+1-000-555-1212",
      "contactType":"customer service"
   }
}

```

```
use Melbahja\Seo\Factory;

$schema = Factory::schema('book')
            ->name('The Book Name')
            ->url('https://example.com/books/the-book')
            ->author
                ->set('@type', 'Person')
                ->name('J.D. Jhon')
            ->getRoot();

echo json_encode($schema, JSON_PRETTY_PRINT);
```

**Results:**

```
{
    "@context": "https:\/\/schema.org",
    "@type": "Book",
    "name": "The Book Name",
    "url": "https:\/\/example.com\/books\/the-book",
    "author": {
        "@type": "Person",
        "name": "J.D. Jhon"
    }
}
```

```
use Melbahja\Seo\Factory;

$schema = Factory::schema('product')
            ->image(['https://example.com/image.jpeg', 'https://example.com/2.jpeg'])
            ->name('The Product Name')
            ->description('Product description...')
            ->sku('12828127112')
            ->brand->set('@type', 'Thing')->name('Brand Name')
            ->getParent()->aggregateRating->ratingValue("4.4")->ratingCount("89")
            ->getParent()->review(
            [
                'reviewRating' =>
                [
                    '@type' => 'Rating',
                    'ratingValue' => '4',
                    'bestRating' => '5'
                ],

                'author' =>
                [
                    '@type' => 'Person',
                    'name' => "Mohamed ELbahja"
                ]
            ])
            ->offers
                ->set('@type', 'AggregateOffer')
                ->lowPrice('119.99')
                ->highPrice('200.99')
                ->priceCurrency('USD')
                ->availability('https://schema.org/InStock')
                ->offerCount('100');

echo $schema;
```

**Results:**

```

{
   "@context":"https:\/\/schema.org",
   "@type":"Product",
   "image":[
      "https:\/\/example.com\/image.jpeg",
      "https:\/\/example.com\/2.jpeg"
   ],
   "name":"The Product Name",
   "description":"Product description...",
   "sku":"12828127112",
   "brand":{
      "@type":"Thing",
      "name":"Brand Name"
   },
   "aggregateRating":{
      "@type":"AggregateRating",
      "ratingValue":"4.4",
      "ratingCount":"89"
   },
   "review":{
      "reviewRating":{
         "@type":"Rating",
         "ratingValue":"4",
         "bestRating":"5"
      },
      "author":{
         "@type":"Person",
         "name":"Mohamed ELbahja"
      }
   },
   "offers":{
      "@type":"AggregateOffer",
      "lowPrice":"119.99",
      "highPrice":"200.99",
      "priceCurrency":"USD",
      "availability":"https:\/\/schema.org\/InStock",
      "offerCount":"100"
   }
}

```

#### 🛀 Meta Tags

[](#-meta-tags)

```
use Melbahja\Seo\Factory;

$metatags = Factory::metaTags(
[
	'title' => 'My new article',
	'description' => 'My new article about how php is awesome',
	'keywords' => 'php, programming',
	'robots' => 'index, nofollow',
	'author' => 'Mohamed Elbahja'
]);

echo $metatags;
```

**Results:**

```

```

```
use Melbahja\Seo\Factory;

$metatags = Factory::metaTags();

$metatags->meta('author', 'Mohamed Elabhja')
		->meta('title', 'PHP SEO')
		->meta('description', 'This is my description')
		->image('https://avatars3.githubusercontent.com/u/8259014')
		->mobile('https://m.example.com')
		->url('https://example.com')
		->shortlink('https://git.io/phpseo')
		->amp('https://amp.example.com')
		->facebook('prop', 'propValue example og')
		->twitter('prop', 'propValue example twitter');

echo $metatags;
```

**Results:**

```

```

#### 🗺 Sitemaps

[](#-sitemaps)

```
$yourmap = Factory::sitemap(string $url, array $options = []): SitemapIndexInterface
```

Option nameDescriptionRequired ?Defaultsave\_pathGenerated sitemaps storage pathYESsitemaps\_urlSitemap index custom url for generated sitemapsNO$urlindex\_nameCustom sitemap index nameNOsitemap.xml##### Simple Example

[](#simple-example)

```
use Melbahja\Seo\Factory;

$sitemap = Factory::sitemap('https://example.com', ['save_path' => '/path/to_save/files']);

$sitemap->links('blog.xml', function($map)
{
    $map->loc('/blog')->freq('daily')->priority('0.8')
        ->loc('/blog/my-new-article')->freq('weekly')->lastMode('2019-03-01')
        ->loc('/اهلا-بالعالم')->freq('weekly');
    $map->loc('/blog/hello')->freq('monthly');
});

// return bool
// throws SitemapException if save_path options not exists
$sitemap->save();
```

**Results:** (📂 in: /path/to\_save/files/)

📁: sitemap.xml (formatted)

```

        https://example.com/blog.xml
        2019-03-01T14:38:02+01:00

```

📁: blog.xml (formatted)

```

      https://example.com/blog
      daily
      0.8

      https://example.com/blog/my-new-article
      weekly
      2019-03-01T00:00:00+01:00

      https://example.com/%D8%A7%D9%87%D9%84%D8%A7-%D8%A8%D8%A7%D9%84%D8%B9%D8%A7%D9%84%D9%85
      weekly

      https://example.com/blog/hello
      monthly

```

##### Multipe Sitemaps &amp;&amp; Images

[](#multipe-sitemaps--images)

```
use Melbahja\Seo\Factory;

$sitemap = Factory::sitemap('https://example.com');

// Instead of passing save_path to the factory you can set it later via setSavePath
// also $sitemap->getSavePath() method to get the current save_path
$sitemap->setSavePath('your_save/path');

// changing sitemap index name
$sitemap->setIndexName('index.xml');

// For images you need to pass a option images => true
$sitemap->links(['name' => 'blog.xml', 'images' => true], function($map)
{
    $map->loc('/blog')->freq('daily')->priority('0.8')
        ->loc('/blog/my-new-article')
            ->freq('weekly')
            ->lastMode('2019-03-01')
            ->image('/uploads/image.jpeg', ['caption' => 'My caption'])
        ->loc('/اهلا-بالعالم')->freq('weekly');

    // image(string $url, array $options = []), image options: caption, geo_location, title, license
    // see References -> images
    $map->loc('/blog/hello')->freq('monthly')->image('https://cdn.example.com/image.jpeg');
});

// another file
$sitemap->links('blog_2.xml', function($map)
{
	// Mabye you need to loop through posts form your database ?
	foreach (range(0, 4) as $i)
	{
		$map->loc("/posts/{$i}")->freq('weekly')->priority('0.7');
	}
});

$sitemap->save();
```

**Results**

📁: index.xml

```

        https://example.com/blog.xml
        2019-03-01T15:13:22+01:00

        https://example.com/blog_2.xml
        2019-03-01T15:13:22+01:00

```

📁: blog.xml

```

        https://example.com/blog
        daily
        0.8

        https://example.com/blog/my-new-article
        weekly
        2019-03-01T00:00:00+01:00

            My caption
            https://example.com/uploads/image.jpeg

        https://example.com/%D8%A7%D9%87%D9%84%D8%A7-%D8%A8%D8%A7%D9%84%D8%B9%D8%A7%D9%84%D9%85
        weekly

        https://example.com/blog/hello
        monthly

            https://cdn.example.com/image.jpeg

```

📁: blog\_2.xml

```

        https://example.com/posts/0
        weekly
        0.7

        https://example.com/posts/1
        weekly
        0.7

        https://example.com/posts/2
        weekly
        0.7

        https://example.com/posts/3
        weekly
        0.7

        https://example.com/posts/4
        weekly
        0.7

```

##### Sitemap with videos

[](#sitemap-with-videos)

```
$sitemap = Factory::sitemap('https://example.com')
                ->setSavePath('./storage/sitemaps')
                ->setSitemapsUrl('https://example.com/sitemaps')
                ->setIndexName('index.xml');

$sitemap->links(['name' => 'posts.xml', 'videos' => true], function($map)
{
	$map->loc('/posts/clickbait-video')->video('My Clickbait Video title',
	[
		// or thumbnail_loc
		'thumbnail' => 'https://example.com/thumbnail.jpeg',
		'description' => 'My description',
		// player_loc or content_loc one of them is required
		'player_loc' => 'https://example.com/embed/81287127'

		// for all availabe options see References -> videos
	]);

	$map->loc('posts/bla-bla');
});

$sitemap->save();
```

**Results**

📁: index.xml

```

        https://example.com/sitemaps/posts.xml
        2019-03-01T15:30:02+01:00

```

**Note:** lastmod in sitemap index files are generated automatically

📁: posts.xml

```

        https://example.com/posts/clickbait-video

            My description
            https://example.com/embed/81287127
            My Clickbait Video title
            https://example.com/thumbnail.jpeg

        https://example.com/posts/bla-bla

```

##### News Sitemaps

[](#news-sitemaps)

```
use Melbahja\Seo\Factory;

$sitemap = Factory::sitemap('https://example.com',
[
	// You can also customize your options by passing array to the factory like this
	'save_path' => './path',
	'sitemaps_url' => 'https://example.com/maps',
	'index_name' => 'news_index.xml'
]);

$sitemap->news('my_news.xml', function($map)
{
    // publication: name, language
    // Google quote about the name: "It must exactly match the name as
    // it appears on your articles on news.google.com"
    $map->setPublication('PHP NEWS', 'en');

    $map->loc('/news/12')->news(
    [
       'title' => 'PHP 8 Released',
       'publication_date' => '2019-03-01T15:30:02+01:00',
    ]);

    $map->loc('/news/13')->news(
    [
        'title' => 'PHP 8 And High Performance',
        'publication_date' => '2019-04-01T15:30:02+01:00'
    ]);
});

$sitemap->save();
```

**Results**

📁: news\_index.xml

```

        https://example.com/maps/my_news.xml
        2019-03-01T15:57:10+01:00

```

📁: my\_news.xml

```

        https://example.com/news/12

                PHP NEWS
                en

            PHP 8 Released
            2019-03-01T15:30:02+01:00

        https://example.com/news/13

                PHP NEWS
                en

            PHP 8 And High Performance
            2019-04-01T15:30:02+01:00

```

**Google quote:** ⚠ "If you submit your News sitemap before your site has been reviewed and approved by our team, you may receive errors." ⚠

#### 🤖 Send Sitemaps To Search Engines

[](#-send-sitemaps-to-search-engines)

According to the sitemaps protocol, search engines should have a url that allow you to inform them about your new sitemap files. like: &lt;searchengine\_URL&gt;/ping?sitemap=sitemap\_url

```
use Melbahja\Seo\Factory;

// the void method send() will inform via CURL: google, bing and yandex about your new file
Factory::ping()->send('https://example.com/sitemap_file.xml');
```

TODOs:
------

[](#todos)

New features coming in v1.1

- Add robots.txt builder
- Add validation for image options
- Add support for video restriction
- Add more tests
- Add a simple integration for frameworks (🍮cakephp and 🔦laravel)
- Add a better documentation
- Your suggestions \[Open new issue 🤔\]

References
----------

[](#references)

- [Sitemaps protocol (https://www.sitemaps.org/protocol.html)](https://www.sitemaps.org/protocol.html)
- [Build Sitemaps (https://support.google.com/webmasters/answer/183668?hl=en)](https://support.google.com/webmasters/answer/183668?hl=en)
- [News Sitemaps (https://support.google.com/webmasters/answer/74288)](https://support.google.com/webmasters/answer/74288)
- [Image Sitempas (https://support.google.com/webmasters/answer/178636)](https://support.google.com/webmasters/answer/178636)
- [Video Sitemaps (https://support.google.com/webmasters/answer/80471)](https://support.google.com/webmasters/answer/80471)
- [Mobile (https://developers.google.com/search/mobile-sites/mobile-seo/other-devices)](https://developers.google.com/search/mobile-sites/mobile-seo/other-devices)

License:
--------

[](#license)

[MIT](https://github.com/melbahja/seo/blob/master/LICENSE) Copyright (c) 2019 Mohamed Elbahja

###  Health Score

30

—

LowBetter than 64% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity15

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity65

Established project with proven stability

 Bus Factor1

Top contributor holds 93.3% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~7 days

Recently: every ~0 days

Total

22

Last Release

2493d ago

PHP version history (2 changes)v1.0.0PHP &gt;=7.1

v1.03PHP &gt;=5.4

### Community

Maintainers

![](https://www.gravatar.com/avatar/45f6b6c7e626ac1ec6470ac4fcfb1e070473b8306149a211467562f8c8308196?d=identicon)[jacky525](/maintainers/jacky525)

---

Top Contributors

[![jacky525](https://avatars.githubusercontent.com/u/50568155?v=4)](https://github.com/jacky525 "jacky525 (28 commits)")[![melbahja](https://avatars.githubusercontent.com/u/8259014?v=4)](https://github.com/melbahja "melbahja (2 commits)")

---

Tags

seoopen-graphmeta-tagsschema.orgsitemapssitemap indexsearch engine optimizationsitemap.xmltwitter tagsphp54

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/jacky525-seo/health.svg)

```
[![Health](https://phpackages.com/badges/jacky525-seo/health.svg)](https://phpackages.com/packages/jacky525-seo)
```

###  Alternatives

[melbahja/seo

SEO library for PHP is a simple PHP library to help developers 🍻 do better on-page SEO optimizations.

355143.7k4](/packages/melbahja-seo)[coffeecode/optimizer

Optimizer makes it easy to bookmark your site tags, open graph and twitter card

28260.9k2](/packages/coffeecode-optimizer)[devrabiul/laravel-seo-manager

Laravel SEO Manager is an SEO tool that improves SEO by adding recommended meta tags.

404.8k](/packages/devrabiul-laravel-seo-manager)[larament/seokit

A complete SEO package for Laravel, covering everything from meta tags to social sharing and structured data.

411.9k](/packages/larament-seokit)[pedroborges/meta-tags

HTML meta tags generator for PHP.

4628.6k1](/packages/pedroborges-meta-tags)[davmixcool/laravel-meta-manager

Laravel Meta Manager is an SEO tool that is used to improve SEO of a website or specific page by adding recommended meta tags to your application.

15040.8k1](/packages/davmixcool-laravel-meta-manager)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
