PHPackages                             asika/sitemap - 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. asika/sitemap

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

asika/sitemap
=============

PHP Simple Sitemap Generator

2.2.0(9mo ago)1918.0k↓28.1%3[2 issues](https://github.com/asika32764/php-sitemap/issues)MITPHPPHP &gt;=8.1CI passing

Since Jun 7Pushed 9mo ago1 watchersCompare

[ Source](https://github.com/asika32764/php-sitemap)[ Packagist](https://packagist.org/packages/asika/sitemap)[ Docs](https://github.com/asika32764/php-sitemap)[ RSS](/packages/asika-sitemap/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (5)Dependencies (4)Versions (6)Used By (0)

PHP Sitemap
===========

[](#php-sitemap)

[![GitHub Actions Workflow Status](https://camo.githubusercontent.com/d2ebbb913dec31b7625bdf4108544adb7de151a94c40f7068fcf06da54d4df95/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f6173696b6133323736342f7068702d736974656d61702f63692e796d6c3f7374796c653d666f722d7468652d6261646765)](https://camo.githubusercontent.com/d2ebbb913dec31b7625bdf4108544adb7de151a94c40f7068fcf06da54d4df95/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f6173696b6133323736342f7068702d736974656d61702f63692e796d6c3f7374796c653d666f722d7468652d6261646765)[![Packagist Version](https://camo.githubusercontent.com/c3a5c4e8612bace931ddc7bb6aa40a9f24488e5ba60e92e5c95f2f9c71910a59/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6173696b612f736974656d61703f7374796c653d666f722d7468652d6261646765)](https://packagist.org/packages/asika/sitemap)[![Packagist Downloads](https://camo.githubusercontent.com/1d00b2f35a6ab9b4f4a7d3f0bb53304bdcd64c5abf2acdcbd2f67aa02c3d36c4/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6173696b612f736974656d61703f7374796c653d666f722d7468652d6261646765)](https://packagist.org/packages/asika/sitemap)

PHP Simple Sitemap Generator. Follows the [W3C Sitemap Protocol](http://www.sitemaps.org/protocol.html)

- [PHP Sitemap](#php-sitemap)
    - [Installation via Composer](#installation-via-composer)
    - [Getting Started](#getting-started)
        - [Render it to XML:](#render-it-to-xml)
    - [Arguments](#arguments)
        - [loc](#loc)
        - [changefreq](#changefreq)
        - [priority](#priority)
        - [lastmod](#lastmod)
    - [Google News Sitemap](#google-news-sitemap)
    - [Using Sitemap index files (to group multiple sitemap files)](#using-sitemap-index-files-to-group-multiple-sitemap-files)
    - [More](#more)

Installation via Composer
-------------------------

[](#installation-via-composer)

```
composer require asika/sitemap
```

Getting Started
---------------

[](#getting-started)

Create a sitemap object:

```
use Asika\Sitemap\Sitemap;

$sitemap = new Sitemap();
```

Add items to sitemap:

```
$sitemap->addItem($url);
$sitemap->addItem($url);
$sitemap->addItem($url);
```

You can add some optional params.

```
use Asika\Sitemap\ChangeFreq;

$sitemap->addItem($url, '1.0', ChangeFreq::DAILY, '2015-06-07 10:51:20');
$sitemap->addItem($url, '0.7', ChangeFreq::WEEKLY, new \DateTime('2015-06-03 11:24:20'));
```

The arguments are `loc`, `priority`, `changefreq` and `lastmod`. See this table:

ParamsRequiredDescription`loc`requiredURL of the page. This URL must begin with the protocol (such as http) and end with a trailing slash, if your web server requires it. This value must be less than 2,048 characters.`priority`optionalThe priority of this URL relative to other URLs on your site. Valid values range from 0.0 to 1.0. This value does not affect how your pages are compared to pages on other sites—it only lets the search engines know which pages you deem most important for the crawlers.`changefreq`optionalHow frequently the page is likely to change. This value provides general information to search engines and may not correlate exactly to how often they crawl the page.`lastmod`optionalThe date of last modification of the file. This date should be in [W3C Datetime format](http://www.w3.org/TR/NOTE-datetime). This format allows you to omit the time portion, if desired, and use YYYY-MM-DD.See:

### Render it to XML:

[](#render-it-to-xml)

```
echo $sitemap->render();

// OR

(string) $sitemap;
```

Save to file:

```
$sitemap->save('/path/to/sitemap.xml');

// OR

$file = new SplFileInfo('/path/to/sitemap.xml');

$sitemap->save($file);
```

This is an example to send it as real sitemap for Google or other search engine:

```
header('Content-Type: application/xml');

echo $sitemap;

exit();
```

Use `output()` to instantly print header and XML body:

```
$sitemap->output();

exit();
```

Handle Psr7 Response

```
$response = new Response();

$response = $sitemap->handleResponse($response);

return $response;
```

The XML output in browser:

```

		http://sitemap.io

		http://sitemap.io/foo/bar/?flower=sakura&amp;fly=bird
		daily
		1.0
		2015-06-07T10:51:20+02:00

```

Arguments
---------

[](#arguments)

### loc

[](#loc)

The URL will be auto escaped. For example, the `&`, `>` will convert to `&amp;`, `&gt;`.

If you want to escape it yourself, set auto escape off:

```
$sitemap->setAutoEscape(false);
```

See:

### changefreq

[](#changefreq)

Valid values are:

```
ChangeFreq::ALWAYS;
ChangeFreq::HOURLY;
ChangeFreq::DAILY;
ChangeFreq::WEEKLY;
ChangeFreq::MONTHLY;
ChangeFreq::YEARLY;
ChangeFreq::NEVER;
```

The value `always` should be used to describe documents that change each time they are accessed.

The value `never` should be used to describe archived URLs.

Please note that the value of this tag is considered a hint and not a command. Even though search engine crawlers may consider this information when making decisions, they may crawl pages marked `hourly` less frequently than that, and they may crawl pages marked `yearly` more frequently than that.

Crawlers may periodically crawl pages marked `never` so that they can handle unexpected changes to those pages.

### priority

[](#priority)

The default priority of a page is `0.5`. Please note that the priority you assign to a page is not likely to influence the position of your URLs in a search engine's result pages. Search engines may use this information when selecting between URLs on the same site, so you can use this tag to increase the likelihood that your most important pages are present in a search index. Also, please note that assigning a high priority to all of the URLs on your site is not likely to help you. Since the priority is relative, it is only used to select between URLs on your site.

### lastmod

[](#lastmod)

Your date format will auto convert to [W3c Datetime format](http://www.w3.org/TR/NOTE-datetime). for example, if you send a string look like: `2015-06-07 10:51:20`, Sitemap object will auto convert it to `2015-06-07T10:51:20+02:00`.

You can set the format you want:

```
$sitemap->setDateFormat(\DateTimeInterface::ISO8601);

// OR

$sitemap->setDateFormat('Y-m-d');
```

Google News Sitemap
-------------------

[](#google-news-sitemap)

Please see [Google News Sitemap](https://developers.google.com/search/docs/crawling-indexing/sitemaps/news-sitemap?visit_id=637247859078479568-4208069007&rd=3) document.

```
$sitemap = new \Asika\Sitemap\NewsSitemap();

$sitemap->addItem(
    $url,
    $newsTitle,
    'Publication Name',
    'en-us',
    $publishedDate
);
```

The format:

```

  http://www.example.org/business/article55.html

      The Example Times
      en

    2008-12-23
    Companies A, B in Merger Talks

```

Using Sitemap index files (to group multiple sitemap files)
-----------------------------------------------------------

[](#using-sitemap-index-files-to-group-multiple-sitemap-files)

```
use Asika\Sitemap\SitemapIndex;

$index = new SitemapIndex();

$index->addItem('http://domain.com/sitemap1.xml', $lastmod1);
$index->addItem('http://domain.com/sitemap2.xml', $lastmod2);

echo $index->render();
```

Output:

```

        http://domain.com/sitemap1.xml
        2015-06-07T10:51:20+02:00

		http://domain.com/sitemap2.xml
		2015-06-07T10:51:20+02:00

```

See:

More
----

[](#more)

- [Extending the Sitemaps protocol](http://www.sitemaps.org/protocol.html#extending)

###  Health Score

48

—

FairBetter than 95% of packages

Maintenance55

Moderate activity, may be stable

Popularity35

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity76

Established project with proven stability

 Bus Factor1

Top contributor holds 100% 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 ~929 days

Total

5

Last Release

281d ago

Major Versions

1.0.0 → 2.0.02023-10-02

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/1639206?v=4)[Simon Asika](/maintainers/asika32764)[@asika32764](https://github.com/asika32764)

---

Top Contributors

[![asika32764](https://avatars.githubusercontent.com/u/1639206?v=4)](https://github.com/asika32764 "asika32764 (24 commits)")

---

Tags

php-sitemapsitemapsitemap-generatorsitemap-phpgoogleSitemapseo

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/asika-sitemap/health.svg)

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

###  Alternatives

[arcanedev/seo-helper

SEO Helper is a framework agnostic package that provides tools &amp; helpers for SEO (Laravel supported).

332467.0k4](/packages/arcanedev-seo-helper)[novactive/ezseobundle

Novactive eZ SEO Bundle is an Ibexa Platform bundle for SEO simplications. metas, sitemaps, robots.txt, etc.

26252.0k2](/packages/novactive-ezseobundle)[dmitryd/typo3-dd-googlesitemap

Google sitemaps for TYPO3

24198.0k](/packages/dmitryd-typo3-dd-googlesitemap)[kphoen/sitemap-bundle

Provides a way to create/generate a sitemap using Doctrine, etc.

2444.8k](/packages/kphoen-sitemap-bundle)[fomvasss/laravel-meta-tags

A package to manage SEO (meta-tags, xml-fields, etc.)

3028.9k](/packages/fomvasss-laravel-meta-tags)[kphoen/sitemap-generator

Provides a way to create/generate a sitemap using Propel, Doctrine, etc.

1687.8k4](/packages/kphoen-sitemap-generator)

PHPackages © 2026

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