0

I have created sitemap using this library https://github.com/spatie/laravel-sitemap but i don't want changefreq info.how to disable.can't find in repository

SitemapGenerator::create(url('/'))->writeToFile(public_path('sitemap.xml'));

Result

<url>
    <loc>http://the-frenemy.local</loc>
    <lastmod>2021-04-16T00:00:00+00:00</lastmod>
    <changefreq>daily</changefreq>
    <priority>0.9</priority>
</url>

One more change set priority is 1 only home page.. all other pages set 0.9

apokryfos
  • 38,771
  • 9
  • 70
  • 114
Fredericka Hartman
  • 835
  • 1
  • 7
  • 13

1 Answers1

1

Publish resource views

Then edit file: https://github1s.com/spatie/laravel-sitemap/blob/HEAD/resources/views/url.blade.php

<url>
    @if (! empty($tag->url))
    <loc>{{ url($tag->url) }}</loc>
    @endif
@if (count($tag->alternates))
@foreach ($tag->alternates as $alternate)
    <xhtml:link rel="alternate" hreflang="{{ $alternate->locale }}" href="{{ url($alternate->url) }}" />
    @endforeach
@endif
@if (! empty($tag->lastModificationDate))
    <lastmod>{{ $tag->lastModificationDate->format(DateTime::ATOM) }}</lastmod>
@endif

    // remove this
    @if (! empty($tag->changeFrequency))
    <changefreq>{{ $tag->changeFrequency }}</changefreq>
    @endif
    // remove this

@if (! empty($tag->priority))
    <priority>{{ number_format($tag->priority,1) }}</priority>
    @endif
</url>

  • thanx Chung any idea how to Set priority for different URL's? – Fredericka Hartman Apr 17 '21 at 15:40
  • ```SitemapGenerator::create('https://example.com')->getSitemap()->add(Url::create('/extra-page')->setPriority(0.1))->writeToFile($path); ``` use setPriority method support ```->setPriority(0.1))``` – Chung Nguyễn Trần Apr 18 '21 at 02:44
  • SitemapGenerator::create(url('/'))->getSitemap()->add(Url::create(url('/'))->setPriority(0.9))->writeToFile(public_path('sitemap.xml')); this statement Not changing the Priority of base url – Fredericka Hartman Apr 18 '21 at 05:19
  • @FrederickaHartman To edit it is very complicated, if you know about php, I will explain as follows: $sitemap = SitemapGenerator::create('https://example.com')->getSitemap(); $sitemap is instanceof Spatie\Sitemap\Sitemap. To edit the priority we have to edit each item in array $sitemap->tags. But $tags is protected property and only the getTags method is not supported by the setTags method. – Chung Nguyễn Trần Apr 19 '21 at 08:27
  • So what we do.. $sitemapTags = $sitemap->getTags(); $newSitemap = Sitemap::create(); foreach ($sitemapTags as $tag) { ```$tag->setPriority(0.5);``` $newSitemap->add($tag); } ```$newSitemap->writeToFile($path);``` – Chung Nguyễn Trần Apr 19 '21 at 08:32