sebthom.de

Menu
  • Home
  • About me
  • Imprint
    • Datenschutzerklärung
  • Guestbook
Menu

Making the DD Sitemap Generator Plug-in work with multilingual blogs

Posted on 2008-05-012012-12-18 by sebthom

To create a bilingual blog with WordPress I am using the Language Switcher Plug-in. This plug-in allows you to put content in more than one language into the post title and content fields by surrounding the localized texts with special tags indicating their language (e.g. “[ lang_en]Hello World[ /lang_en][ lang_de]Hallo Welt[ /lang_de]”). When the posts are viewed in the browser the plug-in will determine the active language and strip off the texts specified in all other languages on the fly.

I am using the great DD Sitemap Generator Plug-in for WordPress to automatically render a site map based on the posts, pages and categories created in my blog. The problem however is that the generated site map is not language aware and displays the page/post titles and category names including the tags and the texts of all languages at once.

To solve this I started digging a bit into the code of WordPress and the Language Switcher Plug-in. The Language Switcher Plug-in achieves the on-the-fly processing of multilingual texts by hooking itself into the so called Filters API which is something like an event-based callback mechanism. Plug-ins can signal their interest in a certain text filter event by calling the add_filter(the_event_id, the_name_of_a_function_to_callback) function provided by the WordPress API to register one if it’s functions that will be invoked by WordPress when the filter event occurs. Besides registering for filter events, plug-ins can also fire such events by calling the apply_filters(the_event_id, the_text_to_be_filtered). WordPress will then apply all registered filters to the text passed over and the apply_filters will return a “filtered” version of the passed text. When rendering the title of a post or page WordPress fires the filter event “the_title” allowing plug-ins to process/modify the title before it is actually displayed. Therefore the Language Switcher Plug-in registers itself to this event and a lot of others to be able to strip off the language tags and the texts in languages other than the currently active one.

Unfortunately the DD Sitemap Generator Plug-in is currently not applying the respective filters when rendering the site map. Therefore the Language Switcher Plug-in is not aware of it and as a result the site map shows all translations of a category name or page/post title at the same time no matter which language is currently active.

To solve this problem I analyzed the source code of the DD Sitemap Generator Plug-in and added the missing apply_filters calls where appropriate. You can follow these steps in case you are having the same issue:

  1. Open the file <wordpress_root>/wp-content/plugins/sitemap-generator/sitemap-generator.php (or <wordpress_root>/wp-content/plugins/dd-sitemap-gen/dd-sitemap-gen.php) in an editor
  2. Locate the text
       $tmp_array[‘title’] = $pages[$k]->post_title;
    and replace it with
       $tmp_array[‘title’] = apply_filters(‘the_title’, $pages[$k]->post_title);
  3. Locate the text
       $tmp_array[‘title’] = $cat_data[$c][‘cat_name’];
    and replace it with
       $tmp_array[‘title’] = apply_filters(‘the_category’, $cat_data[$c][‘cat_name’]);
  4. Locate the text
       $tmp_array[‘title’] = $posts[$k]->post_title;
    and replace it with
       $tmp_array[‘title’] = apply_filters(‘the_title’, $posts[$k]->post_title);
  5. Save the file and you are done.

If you are encountering similar problems with other plug-in you can use the same approach to make them play nicely with the Language Switcher Plug-in.

3 thoughts on “Making the DD Sitemap Generator Plug-in work with multilingual blogs”

  1. nlx says:
    16 July 2008 at 8:22 PM

    Good post.

  2. nlx says:
    16 July 2008 at 9:03 PM

    If you have the time and feel like helping me, here the link :
    //wordpress.org/support/topic/189461?replies=1#post-805561

  3. Mathieu says:
    1 October 2008 at 9:27 PM

    for me i make it work with : $tmp_array[‘title’] = apply_filters(‘widget_title’, $pages[$k]->post_title);

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Language

    English English    Deutsch Deutsch    

Categories

  • IT (25)
    • Development (15)
      • Java (7)
      • Jython (3)
      • Visual Basic (5)
    • Freeware Tips (1)
    • Linux (3)
    • WebSphere Portal (2)
    • Windows (1)
    • Wordpress (4)
  • My Freeware (2)
  • My Music (3)

Recent Posts

  • [Solved] Windows 7 “Safely Remove Hardware” pop-up menu horrendously slow
  • Bash: Capturing stderr in a variable while still printing to the console.
  • Configuring EMF Teneo with Hibernate, Commons DBCP, Spring Hibernate Transaction Manager, and the OpenSessionInViewFilter
  • Using EMF ECore model objects with Wicket components
  • Installing Tomcat 6 on Debian Squeeze
  • Leveraging PyDev’s auto-completion for indirectly created objects
  • OVal 1.40 released
  • Installing WebSphere Portal in a local network
  • Comparing version numbers in Jython / Python
  • Running TomCat 6 in Debug Mode under Windows

Blogroll

  • E L S U A
  • elektrofever.de
  • OVal
  • Sweettt.com
  • Twins’ Running Blog

Recent Comments

  • Luis Diego Villarreal on Excel – VBA Timer Example v1.0.1
  • jonathan on Guestbook
  • Pierre on Lotus Notes’ [Send only] and [Send and File] buttons for Outlook 2003
  • Yereverluvinunclebert on MyPad v1.1.6 – a PHP Editor
  • Sebastian Thomschke on MyPad v1.1.6 – a PHP Editor

Archives

  • May 2012
  • January 2011
  • October 2010
  • September 2010
  • March 2010
  • February 2010
  • September 2009
  • July 2009
  • March 2009
  • February 2009
  • November 2008
  • September 2008
  • May 2008
  • April 2008
  • September 2007
  • July 2007
  • July 2004
  • March 2003
  • August 2002
  • April 2002
  • January 2002
© 2021 sebthom.de | Powered by Minimalist Blog WordPress Theme