Skip to content

Instantly share code, notes, and snippets.

@subharanjanm
Last active June 1, 2016 07:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save subharanjanm/885a0e7a63ad8d4f142c545221ea7e0c to your computer and use it in GitHub Desktop.
Save subharanjanm/885a0e7a63ad8d4f142c545221ea7e0c to your computer and use it in GitHub Desktop.
Adds a new sitemap entry for Axelerant Presentation Slides into the sitemap index created by Yoast SEO plugin. `wpseo_sitemap_index` , `wpseo_enable_xml_sitemap_transient_caching`
<?php
/**
* Plugin Name: AXL Slides Sitemap
* Plugin URI: https://gist.github.com/subharanjanm/885a0e7a63ad8d4f142c545221ea7e0c
* Description: Adds a new sitemap entry for Axelerant Presentation Slides into the sitemap index created by Yoast SEO plugin.
* Version: 1.0
* Author: Subharanjan
* Author URI: https://gist.github.com/subharanjanm/885a0e7a63ad8d4f142c545221ea7e0c
* License: GPLv2 or later
*/
defined( 'ABSPATH' ) or die( "No script kiddies please!" );
function axl_add_sitemap_slides() {
if ( class_exists( 'WPSEO_Sitemaps' ) ) {
$plugin_file = pathinfo( $_SERVER['PHP_SELF'] );
$modification_time = date( "c", filemtime( $plugin_file["basename"] ) );
$slides_sitemap_xml = plugins_url( 'slides-sitemap.xml', __FILE__ );
$slides_sitemap = '<sitemap>' . "\n";
$slides_sitemap .= '<loc>' . $slides_sitemap_xml . '</loc>' . "\n";
$slides_sitemap .= '<lastmod>' . $modification_time . '</lastmod>' . "\n";
$slides_sitemap .= '</sitemap>' . "\n";
return $slides_sitemap;
}
return '';
}
add_filter( 'wpseo_sitemap_index', 'axl_add_sitemap_slides' );
add_filter( 'wpseo_enable_xml_sitemap_transient_caching', '__return_false' );
@subharanjanm
Copy link
Author

Create an xml file with the custom urls and store it somewhere in your server. ( say slides-sitemap.xml ). Use it's path in the above code.

<?xml version="1.0" encoding="UTF-8"?><urlset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xmlns:image="http://www.google.com/schemas/sitemap-image/1.1"
        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">
    <url>
        <loc>https://example.com/wp-content/reference/slides/</loc>
        <lastmod>2016-05-23T04:29:50-04:00</lastmod>
        <changefreq>weekly</changefreq>
        <priority>0.8</priority>
    </url>
    <url>
        <loc>https://example.com/wp-content/reference/slides/TYPO3-Best-Practices</loc>
        <lastmod>2016-05-19T09:04:58-04:00</lastmod>
        <changefreq>weekly</changefreq>
        <priority>0.6</priority>
    </url>
    <url>
        <loc>https://example.com/wp-content/reference/slides/Command-Line-for-Newbies</loc>
        <lastmod>2016-05-19T09:04:58-04:00</lastmod>
        <changefreq>weekly</changefreq>
        <priority>0.6</priority>
    </url>
    <url>
        <loc>https://example.com/wp-content/reference/slides/why-coding-php-fundamentals-short</loc>
        <lastmod>2016-05-19T09:04:58-04:00</lastmod>
        <changefreq>weekly</changefreq>
        <priority>0.6</priority>
    </url>
    <url>
        <loc>https://example.com/wp-content/reference/slides/why-coding-php-fundamentals</loc>
        <lastmod>2016-05-19T09:04:58-04:00</lastmod>
        <changefreq>weekly</changefreq>
        <priority>0.6</priority>
    </url>
</urlset>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment