<?php | |
/********* DO NOT COPY THE PARTS ABOVE THIS LINE *********/ | |
/* Create Custom Yoast Sitemap | |
* Credit: Unknown | |
* Last Tested: Unknown | |
********* | |
* HOW TO USE | |
* Replace TYPE with your custom type | |
*/ | |
add_action( 'init', 'enable_custom_sitemap' ); | |
function enable_custom_sitemap() { | |
global $wpseo_sitemaps; | |
if ( isset( $wpseo_sitemaps ) && ! empty ( $wpseo_sitemaps ) ) { | |
$wpseo_sitemaps->register_sitemap( 'TYPE', 'create_TYPE_sitemap' ); | |
} | |
} |
<?php | |
/********* DO NOT COPY THE PARTS ABOVE THIS LINE *********/ | |
/* Add External Sitemap to Yoast Sitemap Index | |
* Credit: Paul https://wordpress.org/support/users/paulmighty/ | |
* Modified by: Team Yoast | |
* Last Tested: Aug 25 2017 using Yoast SEO 5.3.2 on WordPress 4.8.1 | |
********* | |
* This code adds two external sitemaps and must be modified before using. | |
* Replace http://www.example.com/external-sitemap-#.xml | |
with your external sitemap URL. | |
* Replace 2017-05-22T23:12:27+00:00 | |
with the time and date your external sitemap was last updated. | |
Format: yyyy-MM-dd'T'HH:mm:ssZ | |
* If you have more/less sitemaps, add/remove the additional section. | |
********* | |
* Please note that changes will be applied upon next sitemap update. | |
* To manually refresh the sitemap, please disable and enable the sitemaps. | |
*/ | |
add_filter( 'wpseo_sitemap_index', 'add_sitemap_custom_items' ); | |
function add_sitemap_custom_items( $sitemap_custom_items ) { | |
$sitemap_custom_items .= ' | |
<sitemap> | |
<loc>http://www.example.com/external-sitemap-1.xml</loc> | |
<lastmod>2017-05-22T23:12:27+00:00</lastmod> | |
</sitemap>'; | |
/* Add Additional Sitemap | |
* This section can be removed or reused as needed | |
*/ | |
$sitemap_custom_items .= ' | |
<sitemap> | |
<loc>http://www.example.com/external-sitemap-2.xml</loc> | |
<lastmod>2017-05-22T23:12:27+00:00</lastmod> | |
</sitemap>'; | |
/* DO NOT REMOVE ANYTHING BELOW THIS LINE | |
* Send the information to Yoast SEO | |
*/ | |
return $sitemap_custom_items; | |
} |
<?php | |
/********* DO NOT COPY THE PARTS ABOVE THIS LINE *********/ | |
/* Change the number of entries per sitemap | |
* Credit: Yoast Team | |
* Last Tested: Oct 17 2018 using Yoast SEO 8.4 on WordPress 4.9.8 | |
********* | |
*/ | |
add_filter( 'wpseo_sitemap_entries_per_page', 'max_entries_per_sitemap' ); | |
function max_entries_per_sitemap() { | |
return 10; | |
} |
This comment has been minimized.
This comment has been minimized.
I've been copying and pasting this to my functions.php file with no success. I cannot figure out why it will not run and add additional sitemaps to sitemap_index.xml . This does not work currently, Can we please get someone to fix it? Why doesn't it work? Yoast Version 4.8 even tried version Yoast 5.01 Author, will you please help us? Does this currently work for you in your theme's functions.php, did you add an add_action command or why is this not working for us? |
This comment has been minimized.
This comment has been minimized.
please fix this. |
This comment has been minimized.
This comment has been minimized.
Yes. This code is not working. |
This comment has been minimized.
This comment has been minimized.
@BN83 @Greenlanternfromhouston @maustyle @baqarcodupio Thanks! |
This comment has been minimized.
This comment has been minimized.
I installed and my new sitemap is recognized, but I get the following error message in top of Yoast Dashboard. The following file is blocking your XML sitemaps from working properly. Either delete it (this can be done with the "Fix it" button) or disable Yoast SEO XML sitemaps. Hope someone can help, thanks! |
This comment has been minimized.
This comment has been minimized.
@gdelwo To receive free support for Yoast SEO we have the following channels:
Or if you want personal support via email, you can purchase Yoast SEO Premium. Thanks for your understanding. |
This comment has been minimized.
This comment has been minimized.
What can we add to make this code change the last update date for the external xml link to be more recent as the other xml link is updated? |
This comment has been minimized.
This comment has been minimized.
and by the way - the code DOES work - you need to make sure you are adding it to the theme you are using. IMPORTANT: In your dashboard click themes - then editor - then on the right side click functions file - you can scroll to the very bottom and add the below code and it will work: you can just change your external siemap form what i have to yours - chage this one line (and the date)
You may be adding the code to the wrong functions file if it's not working for you - the below code is what I put in the functions code of theme we are using for https://eyelashr.com - We're the first "Uber for eyelash extensions" platform - if you're searching for eyelash extensions near me - check out htps://eyelashr.com Here's the exact code we put and if you go to https://eyelashr.com/sitemap_index.xml - you'll see the last link as the external link
|
This comment has been minimized.
This comment has been minimized.
Hi dear, |
This comment has been minimized.
This comment has been minimized.
@BVtester This is not the proper place to request support. Please check out our extensive Knowledge Base or visit the free support forum. If you require further support, upgrading to our premium version provides you with access to our support team. |
This comment has been minimized.
This comment has been minimized.
One thing to keep in mind, sitemaps are cached. For development disable it using:
|
This comment has been minimized.
This comment has been minimized.
@janw-oostendorp nailed the issue for me. The code would not call my filter, but disabling the caching corrected the issue. |
This comment has been minimized.
This comment has been minimized.
Thanks, Its working perfect cheers!!!! |
This comment has been minimized.
This comment has been minimized.
Would like to add that this is currently still working with WordPress on 5.0.2 and Yoast plugin on 9.4! |
This comment has been minimized.
This comment has been minimized.
I have 3 questions:
|
This comment has been minimized.
This comment has been minimized.
this code doesn’t work for me, I inserted it into function.php and it doesn’t show me my added sitemap there are 18 of them and it remains to tell me what I'm doing wrong |
This comment has been minimized.
This comment has been minimized.
If you have refreshed the sitemap, this is not the proper place to request support. Please check out our extensive Knowledge Base or visit the free support forum. If you require further support, upgrading to our premium version provides you with access to our support team. |
This comment has been minimized.
This comment has been minimized.
Two new gists as a more comprehensive examples. All in one file, including writing sitemap Sitemap without a data source specified: Sitemap sourced from post type(s): |
This comment has been minimized.
This comment has been minimized.
Does anyone know how to REMOVE the line from the sitemap once you've added it? Even after refreshing the XML Sitemap option, and removing and reinstalling the plugin, that external sitemap is still showing |
This comment has been minimized.
This comment has been minimized.
Removing the code snippet will remove the custom functionality. Additionally, this is not the proper place to request support. Please check out our extensive help section or visit the free support forum. If you require further support, upgrading to our premium version provides you with access to our support team. |
This comment has been minimized.
This comment has been minimized.
@leepowers Thanks for this. This works. |
This comment has been minimized.
This comment has been minimized.
@jack-fdrv |
This comment has been minimized.
This comment has been minimized.
Thank you very much @leepowers! |
This comment has been minimized.
Where should this go? I've put it in my 'wp-content/plugins/wordpress-seo' folder but the sitemap is not listing in my sitemap?