Sitemap Generator

Advertising

Last Updated : |  

Are sitemap generators really a good choice? It all depends on your website, if you have links to external sites or links to social networks (share / follow), then I would say that it is not good to use a sitemap generator. Since any links are included in this sitemap that I have just named and that would not be so cheap compared to Google. You would risk adding too many URLs to your sitemap if you use a generator that does not create a sitemap index or sort it (which is hard for a tool). This would write everything in a file, which would not be bad until 50,000 URLs. But you waste space, in the sitemap have the URLs named above and nothing more to look for.



No control over the sitemap

You have no control and you will have a good red (error) line in your Search Console, because these URLs are for the most part not indexed and you are even devalued by Google therefore. At home you clean up when something is lying around and here it is just as the tools that show you mistakes, they show you not only so, but so that you remove the errors. Why ? Because the bots are prevented from doing your job properly.

Or do you like to work on a full desk?

Just for fun, I used a sitemap generator and thought of it as a developer "Oh shiiiit". So you better leave the fingers of such tools. Because you want to generate a sitemap you create a "collector" so a (garbage) collector :)



How to use Sitemaps in general?

Do something with sitemaps and maybe a small sitemap will be enough for your small website and you can prevent the above mentioned impurities.

If you are using a CMS system then check if there is a good plugin (extension) for it, so read the details, because not every plugin is good.

Plugin / Extension should e.g. bring this:

  • You should be able to choose which
  • pages or posts come into the sitemap
  • The sitemap should update itself automatically
  • Should provide various options, such as optional
  • Work without errors
  • And much more...

Should you bring knowledge that goes beyond what I have just mentioned. So of course you can create and filter your own Dynamic Sitemap.



Create sitemap with PHP

Of course you can also create your sitemap with a programming language, here in the example with PHP. This one works, however, this whole is simply procedurally written down and can be done much better and Object Oriented will create a class from it and more, this one should serve for understanding.

Here we emulate our pages from the database with an array and run them in a loop, so we create the sitemap dynamically. It should create a sitemap index which is not in the example at the moment and then the areas should be split up. That means in the sitemap index sitemaps can be compressed with gzip, like sitemap-pages.xml.gz, sitemap-blog.xml.gz or for pictures and videos sitemap-videos.xml.gz, sitemap -images.xml.gz.

 sitemaps.org


// PHP CODE
     0  <?php  1    2  // This is a small sample and only for the understand  3  header("Content-Type: application/xml; charset=utf-8");  4    5  /**  6   *   7   * @param type $args  8   * @return string  9   */  10  function createURL($args = array()) {  11    12      $output = '';  13    14      $output .= '<url>' . PHP_EOL;  15      $output .= '<loc>' . $args["url"] . '</loc>' . PHP_EOL;  16      $output .= '<lastmod>' . $args["lastmod"] . '</lastmod>' . PHP_EOL;  17      $output .= '<changefreq>' . $args["changefreq"] . '</changefreq>' . PHP_EOL;  18      $output .= '<priority>' . $args["priority"] . '</priority>' . PHP_EOL;  19      $output .= '</url>' . PHP_EOL;  20    21      return $output;  22  }  23    24  // Domain for urls without domain  25  $domain = "localhost";  26    27  // Your sites from db, here we simulate this with an array  28  $sites = array(  29      array(  30          "url" => $domain . "/tests/default",  31          "lastmod" => "005-01-01",  32          "changefreq" => "weekly",  33          "priority" => "0.8",  34      ),  35      array(  36          "url" => $domain . "/tests/practice",  37          "lastmod" => "005-01-01",  38          "changefreq" => "weekly",  39          "priority" => "0.5",  40      ),  41      array(  42          "url" => $domain . "/tests/HTML",  43          "lastmod" => "005-01-01",  44          "changefreq" => "weekly",  45          "priority" => "0.3",  46      )  47  );  48    49  // Sitemap holder for output  50  $sitemap = '';  51  $sitemap .= '<?xml version="1.0" encoding="UTF-8"?>' . PHP_EOL;  52  // Stylesheet for our sitemap for style  53  $sitemap .= '<?xml-stylesheet type="text/css" href="css/mb-sitemap.css"?>';  54  // Url list for our sitemap  55  $sitemap .= '<urlset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd" xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">' . PHP_EOL;  56  // Loop sites and create urls  57  foreach ($sites as $key => $value) {  58      $sitemap .= createURL($value);  59  }  60  $sitemap .= '</urlset>';  61    62  // Wnat you a file, you can write in sitmap.xml  63  //file_put_contents("sitemap.xml", $sitemap);  64  echo $sitemap; 


    XML Sitemap CSS Style

    We can also style our sitemap and prepare it for the issue so that it looks even more chic. At the top of the PHP code the CSS is already included, you can change the name and location.


    // CSS CODE
       0  urlset {  1        2        3  }  4    5  urlset:before {  6        7      content: "Styled Sitemap";  8      padding: 1rem;  9      font-size: 3rem;  10  }  11    12  url {  13        14      display: block;  15      padding: .5rem 1rem;  16      border-top: 1px solid #333;  17  }  18    19  loc {  20        21        22  }  23    24  lastmod {  25        26        27  }  28    29  changefreq {  30        31        32  }  33    34  priority {  35        36        37  } 


      Validate the sitemap

      So you should connect your website to the Google Search Console. If you did, Google will let you know about your sitemap and show you everything you need.

      Advertising

      Your Comment

      * This fields are required, email don't publish
      ?

      This field is optional
      Fill this field link your name to your website.

      Data entered in this contact form will be stored in our system to ensure the output of the comment. Your e-mail address will be saved to determine the number of comments and for registration in the future

      I have read the Privacy policy and Terms. I Confirm the submission of the form and the submission of my data.
      tnado © 2024 | All Rights Reserved
      Made with by prod3v3loper