WordPress.org

Forums

XML Sitemap & Google News feeds
[resolved] [Plugin: XML Sitemap & Google News Sitemap Feeds] Trailing slash with permalink-structure /%post (7 posts)

  1. Bernhard Riedl
    Member
    Posted 3 years ago #

    Hi RavanH,

    Thanks for the multi-site network functionality of your plugin. - It will help to realize the vision of a multi-lingual installation of our current information portal. :)

    As WordPress can sometimes be very greedy on URL-handling, I ran into the following issue comprising the combination your sitemaps(-news).xml redirect and the /%postname%/ permalink structure. FYI: The sitemap serves just fine, but http://mydomain.com/sitemap.xml gets redirected to http://mydomain.com/sitemap.xml/ Please note the trailing slash which some spiders would probably mis-interpret.

    After a bit of research I implemented the following code which seems to solve the problem:

    In the constructor of XMLSitemapFeed.class.php I've added

    // REMOVE TRAILING SLASH
    add_action('pre_get_posts', array(__CLASS__, 'remove_redirect_canonical') );

    And the following function tells WordPress to remove the built-in canonical redirect if we're handling a sitemap-feed.

    //remove trailing slash
    function remove_redirect_canonical() {
    	global $wp_query;
    
    	if (is_feed() && in_array($wp_query->get('feed'), array('sitemap', 'sitemap-news')))
    		remove_action('template_redirect', 'redirect_canonical');
    }

    Hope this will help others, too.

    A feature suggestion: What do you think about an exclude-filter for your query_posts calls? - That way we could easily leave out a list of posts/pages and Google wouldn't return an error in the Webmaster-Tools because a sitemap-item is blocked for example by robots.txt.

    Greetz,
    Berny

    http://wordpress.org/extend/plugins/xml-sitemap-feed/

  2. RavanH
    Member
    Plugin Author

    Posted 3 years ago #

    I've been using WP a long time and the permalink structure /%postname%/ has always caused problems. Not only for plugins but other (even WP internal) functionality too. In fact, I am surprised that up to this day, that permalink structure is still even allowed...

    But ok, I get the point of wanting to use that permalink structure. I would to, if it was not so problematic.

    In any case, I had seen that trailing slash in some other instances as well and had already implemented another workaround in the development version. So I would like to ask you to do a test upgrade to the development version to see if that trailing slash still occurs. If it does, I'll consider your approach as an alternative.

    I'll take the exclude filter in to consideration too. It's not a bad idea and will likely make it into the development version soon :) Would you mind if it would be in the form of a post meta key/value to exclude a posts from the sitemap?

  3. Bernhard Riedl
    Member
    Posted 3 years ago #

    Hi RavanH,

    I've been using WP a long time and the permalink structure /%postname%/ has always caused problems. Not only for plugins but other (even WP internal) functionality too. In fact, I am surprised that up to this day, that permalink structure is still even allowed...

    I agree with you on that. - From a coder's point of view, I also prefer order and hierarchy in pages, posts, archives. Nevertheless, as you've mentioned there are reasons and for which our SEO department needs such a link-'structure'.

    So I would like to ask you to do a test upgrade to the development version to see if that trailing slash still occurs.

    I installed your dev-version on our staging-server after having a look onto your source code. - Nice idea. - Your function also protects other 'generated files' from being trail-slashed and it works great over here. :)

    I'll take the exclude filter in to consideration too. It's not a bad idea and will likely make it into the development version soon :) Would you mind if it would be in the form of a post meta key/value to exclude a posts from the sitemap?

    Perfect and thanks. I'm not sure what you mean by post meta key/value? Or do you also plan to block pages by slug and not only by Ids?

    Greetz,
    Berny

  4. RavanH
    Member
    Plugin Author

    Posted 3 years ago #

    Hi Bernard,

    Good to hear it works :)

    With "exclude by post meta key/value" I mean that giving a post or page a custom meta key like "sitemap_exclude" and value "yes" (or 1) would make that post/page be excluded from the sitemap...

    I do not have time the coming weeks to work on it but as soon as any of this is in the dev version, I'll let you know. Maybe send me a reminder if you don't hear from me for too long ;)

  5. Bernhard Riedl
    Member
    Posted 3 years ago #

    Hi RavanH,

    That's a sound idea. - I will forward your plans to my SEO guys who will be happy about it. :)

    Greetz,
    Berny

  6. Bernhard Riedl
    Member
    Posted 3 years ago #

    Hi RavanH,

    Your plugin currently supplies the XML-sitemap for about 10 apps in our realm. :)

    With "exclude by post meta key/value" I mean that giving a post or page a custom meta key like "sitemap_exclude" and value "yes" (or 1) would make that post/page be excluded from the sitemap...

    I do not have time the coming weeks to work on it but as soon as any of this is in the dev version, I'll let you know. Maybe send me a reminder if you don't hear from me for too long ;)

    Did you have time to look into my feature request?

    Greetz,
    Berny

  7. RavanH
    Member
    Plugin Author

    Posted 3 years ago #

    Hi Bernhard, thank you for your donation! :)

    I did not have time yet but the plugin is up for an update fairly soon. Along with a meta key to set the Genre for each post in the Google News sitemap, I will be adding the exclude option for sure.

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic