News | laravel-sitemap | Spatie

 SPATIE

  Laravel Sitemap
==================

spatie.be/open-source

  [Docs](https://spatie.be/docs)  [Laravel-sitemap](https://spatie.be/docs/laravel-sitemap/v8)  Adding-content-to-urls  News

 Version   v8

 Other versions for crawler [v8](https://spatie.be/docs/laravel-sitemap/v8)

- [ Introduction ](https://spatie.be/docs/laravel-sitemap/v8/introduction)
- [ Installation &amp; setup ](https://spatie.be/docs/laravel-sitemap/v8/installation-setup)
- [ Support us ](https://spatie.be/docs/laravel-sitemap/v8/support-us)
- [ Changelog ](https://spatie.be/docs/laravel-sitemap/v8/changelog)
- [ Questions and issues ](https://spatie.be/docs/laravel-sitemap/v8/questions-issues)
- [ About us ](https://spatie.be/docs/laravel-sitemap/v8/about-us)

Creating sitemaps
-----------------

- [ Generating a sitemap ](https://spatie.be/docs/laravel-sitemap/v8/creating-sitemaps/generating-a-sitemap)
- [ Manually creating a sitemap ](https://spatie.be/docs/laravel-sitemap/v8/creating-sitemaps/manually-creating-a-sitemap)
- [ Creating a sitemap index ](https://spatie.be/docs/laravel-sitemap/v8/creating-sitemaps/creating-a-sitemap-index)
- [ Splitting large sitemaps ](https://spatie.be/docs/laravel-sitemap/v8/creating-sitemaps/splitting-large-sitemaps)
- [ Adding an XSL stylesheet ](https://spatie.be/docs/laravel-sitemap/v8/creating-sitemaps/adding-an-xsl-stylesheet)
- [ Returning a response ](https://spatie.be/docs/laravel-sitemap/v8/creating-sitemaps/returning-a-response)
- [ Sorting URLs ](https://spatie.be/docs/laravel-sitemap/v8/creating-sitemaps/sorting-urls)

Customizing the crawler
-----------------------

- [ Crawl profiles ](https://spatie.be/docs/laravel-sitemap/v8/customizing-the-crawler/crawl-profiles)
- [ Filtering URLs ](https://spatie.be/docs/laravel-sitemap/v8/customizing-the-crawler/filtering-urls)
- [ Configuring the crawler ](https://spatie.be/docs/laravel-sitemap/v8/customizing-the-crawler/configuring-the-crawler)

Adding content to URLs
----------------------

- [ Alternates ](https://spatie.be/docs/laravel-sitemap/v8/adding-content-to-urls/alternates)
- [ Images ](https://spatie.be/docs/laravel-sitemap/v8/adding-content-to-urls/images)
- [ Videos ](https://spatie.be/docs/laravel-sitemap/v8/adding-content-to-urls/videos)
- [ News ](https://spatie.be/docs/laravel-sitemap/v8/adding-content-to-urls/news)
- [ Sitemapable models ](https://spatie.be/docs/laravel-sitemap/v8/adding-content-to-urls/sitemapable-models)

Advanced usage
--------------

- [ Scheduled generation ](https://spatie.be/docs/laravel-sitemap/v8/advanced-usage/scheduled-generation)
- [ Writing to disks ](https://spatie.be/docs/laravel-sitemap/v8/advanced-usage/writing-to-disks)

 News
====

You can add Google News tags to URLs. See the [Google News Sitemaps documentation](https://developers.google.com/search/docs/crawling-indexing/sitemaps/news-sitemap) for more information.

```
use Carbon\Carbon;
use Spatie\Sitemap\Sitemap;
use Spatie\Sitemap\Tags\Url;

Sitemap::create()
    ->add(
        Url::create('https://example.com/news-article')
            ->addNews('Publication Name', 'en', 'Article title', Carbon::now())
    )
    ->writeToFile($sitemapPath);
```

You can also pass optional parameters like `access` and `genres`:

```
use Carbon\Carbon;
use Spatie\Sitemap\Sitemap;
use Spatie\Sitemap\Tags\News;
use Spatie\Sitemap\Tags\Url;

$options = [
    'access' => News::OPTION_ACCESS_SUB,
    'genres' => implode(', ', [News::OPTION_GENRES_BLOG, News::OPTION_GENRES_OPINION]),
];

Sitemap::create()
    ->add(
        Url::create('https://example.com/news-article')
            ->addNews('Publication Name', 'en', 'Article title', Carbon::now(), $options)
    )
    ->writeToFile($sitemapPath);
```
