Image

Sitemaper

A very flexible PHP sitemap generator library to suit all your sitemap needs

Sitemap PHP Sitemap Generator

Support for Google Sitemap Extesions

The XML transformer built with Sitemaper supports Google sitemap extensions which are the following:

  • Images
  • Videos
  • News

You can learn more about Google sitemap extensions here

Images

Learn the complete attributes for image sitemap extension here

use Alexecus\Sitemaper\Sitemap;

$sitemap = new Sitemap('http://mysite.com');

$sitemap
    ->addItem('/', [
        'lastmod' => '2020-05-15',
        'changefreq' => 'monthly',
        'priority' => '1.0',

        'image' => [
            'loc' => 'http://mysite.com/image.png',
        ],
    ]);

This will produce the following Sitemap XML. Sitemaper automatically detects that you wanted an image tag so it puts the proper attributes and the proper tags

<?xml version="1.0" encoding="UTF-8"?>
<urlset
    xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"
    xmlns:image="http://www.google.com/schemas/sitemap-image/1.1"
>
  <url>
    <loc>http://mysite.com/</loc>
    <lastmod>2020-05-15</lastmod>
    <changefreq>monthly</changefreq>
    <priority>1.0</priority>
    <image:image>
      <image:loc>http://mysite.com/image.png</image:loc>
    </image:image>
  </url>
</urlset>

Videos

Learn the complete attributes for video sitemap extension here

use Alexecus\Sitemaper\Sitemap;

$sitemap = new Sitemap('http://mysite.com');

$sitemap
    ->addItem('/', [
        'lastmod' => '2020-05-15',
        'changefreq' => 'monthly',
        'priority' => '1.0',

        'video' => [
            'title' => 'My Video',
            'description' => 'This is my description',
            'content_loc' => 'http://mysite.com/video.mp4',
        ],
    ]);

This will produce the following XML

<?xml version="1.0" encoding="UTF-8"?>
<urlset
    xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"
    xmlns:video="http://www.google.com/schemas/sitemap-video/1.1"
>
  <url>
    <loc>http://mysite.com/</loc>
    <lastmod>2020-05-15</lastmod>
    <changefreq>monthly</changefreq>
    <priority>1.0</priority>
    <video:video>
      <video:title>My Video</video:title>
      <video:description>This is my description</video:description>
      <video:loc>http://mysite.com/video.mp4</video:loc>
    </video:video>
  </url>
</urlset>

News

Learn the complete attributes for news sitemap extension here

use Alexecus\Sitemaper\Sitemap;

$sitemap = new Sitemap('http://mysite.com');

$sitemap
    ->addItem('/', [
        'lastmod' => '2020-05-15',
        'changefreq' => 'monthly',
        'priority' => '1.0',

        'news' => [
            'title' => 'My News',
            'publication' => [
                'name' => 'The Example Times',
                'language' => 'en',
            ],
        ],
    ]);

This will produce the following XML

<?xml version="1.0" encoding="UTF-8"?>
<urlset
    xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"
    xmlns:video="http://www.google.com/schemas/sitemap-video/1.1"
>
  <url>
    <loc>http://mysite.com/</loc>
    <lastmod>2020-05-15</lastmod>
    <changefreq>monthly</changefreq>
    <priority>1.0</priority>
    <news:news>
      <news:title>My News</news:title>
        <news:publication>
          <news:name>The Example Times</news:name>
          <news:language>en</news:language>
        </news:publication>
    </news:news>
  </url>
</urlset>