Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Besides the urls of posts, pages and categories, I need my site's sitemap to include the urls of various pages that display data coming from an external source other than the WP database (Rails API).

Is there a hook to which I can add a filter so that once Dynamic Sitemap Generation takes place, I can then append these other urls to the sitemap.

PS: I had a suggestion to use aiosp_sitemap_post_filter, but there is no doc on how it works.

Thanks

UPDATE

with aiosp_sitemap_post_filter you can add only other posts to the sitemap and no custom content.

share|improve this question
    
Not sure if this helps, but I use an events plugin and generate my old sitemaps for the events as a standalone sitemap and use the Google XML Sitemaps plugin for my posts/pages/cats, etc. I can share that code if you're interested –  TomC Apr 2 at 13:07
    
Yes please, it's maybe a better solution to have 2 different sitemaps. –  Pietro Apr 2 at 14:09
1  
You can find it here: e-dynamics.be/bbpress/topic.php?id=1801 –  TomC Apr 3 at 7:19

2 Answers 2

This is not a solution to my question but it helps me to solve my problem in Wordpress, and I want to share it.

I create a separate sitemap using XMLWriter. Here is the code.

Wordpress hook:

add_action('parse_request', 'my_custom_url_handler');

function my_custom_url_handler() {
    $c = new EventsSitemapBuilder();
    if( $_SERVER["REQUEST_URI"] == '/website/events-sitemap.xml') {
        header("Content-type: text/xml");
        $c = new EventsSitemapBuilder();
        $c->build();
    }
    exit;
}

EventsSitemapBuilder():

class EventsSitemapBuilder {

        private $api_client;
        private $sitemap_data;
        private $sm_xml_writer;


        public function __construct() {
            $this->api_client = new ALApiClient();
            $this->sitemap_data = $this->api_client->sitemap_data();
            $this->sm_xml_writer = new XMLWriter();
        }


        public function build() {
            //events.id, it_texts.slug AS it_slug, en_texts.slug AS en_slug, events.updated_at
            //$this->sm_xml_writer->openUri( home_url( "events-sitemap" ) );
            $this->sm_xml_writer->openUri( "php://output" );
            $this->sm_xml_writer->startDocument('1.0', 'UTF-8');
            $this->sm_xml_writer->startElement('urlset');
            $this->sm_xml_writer->writeAttribute('xmlns', "http://www.sitemaps.org/schemas/sitemap/0.9");

            array_map( array( $this, 'sitemap_event_entry' ), $this->sitemap_data );

            $this->sm_xml_writer->endElement();
            $this->sm_xml_writer->endDocument();
            $this->sm_xml_writer->flush();
        }


        private function sitemap_event_entry( $data ) {
            $this->sm_xml_writer->startElement('url');
            $this->sm_xml_writer->writeElement('lastmod', $data['date']);
            $this->sm_xml_writer->writeElement('changefreq', 'weekly');
            $this->sm_xml_writer->writeElement('priority', 0.6);
            $event_url = home_url( 'events/' . $data['id']  );
            $this->sm_xml_writer->writeElement('loc', $data['url'] );
            $this->sm_xml_writer->endElement();
        }
    }
share|improve this answer
up vote 0 down vote accepted

This is the solution from Peter Baylies (Plugin Author)

add_filter( 'option_aioseop_options', 'itdge_sitemap_addl_pages' );

function itdge_sitemap_addl_pages( $option ) {
    if (   !empty( $option )
        && !empty( $option['modules'] )
        && !empty( $option['modules']['aiosp_sitemap_options'])
      ) {
        $my_sitemap_entries = Array(
        '/test1' => Array( 'prio' => '0.1', 'freq' => 'daily', 'mod' => '2014-04-01' ),
        '/test2' => Array( 'prio' => '0.3', 'freq' => 'weekly', 'mod' => '2014-03-02' )
        );
        if ( empty( $option['modules']['aiosp_sitemap_options']['aiosp_sitemap_addl_pages'] ) ) {
            $option['modules']['aiosp_sitemap_options']['aiosp_sitemap_addl_pages'] = Array();
        }
        foreach( $my_sitemap_entries as $k => $v ) {
            $option['modules']['aiosp_sitemap_options']['aiosp_sitemap_addl_pages'][$k] = $v;
        }
    }
    return $option;
}
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.