Support » Plugin: Polylang » Monthly archives

  • Resolved Carlos



    I have been using Polylang for a few weeks and it is working beautifully. Thank you!

    I have a website in Spanish and I have translated it to Catalan without problems. In the website I have a blog too, only in Spanish. I have plans to translate all entries to Catalan, but in the future I won’t post the same things in both, nor in the same dates.

    I found a problem while exploring posts by month. For example, if you go here:

    You can see the posts of this month. If I switch to Catalan, I have a 404, because there are no posts for this month. However, if you go to a single post ( non translated yet ): and switch to Catalan, you will be redirected to the home page ( I kind of like this behavior ).

    Is there any way to use this same functionality while exploring monthly archives or am I missing something?

    I have the latest Polylang version.

    1.- Permalinks: /blog/%postname%
    2.- I am using a static front page, overriden by the Responsive Theme
    3.- My Polylang settings are:

    – Default language: Spanish
    – Detect language: False
    – URL modifications:

    – Media: True
    – Sync: All true
    – Custom types: All false

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author Chouby


    Yes, Polylang works like this since the beginning for all archives (date, author, post type…). I preferred doing so because ckecking for the existence of archives in the other languages needs one query per language (and I am aware of sites using 7 languages!). I wanted to avoid this performance penalty. However, to be honest I did not measure it 😉 Up to now you are the first to ask about this:

    You can add this in your functions.php or in a custom plugin:

    add_filter('pll_language_link', 'check_archive_translation');
    function check_archive_translation($url, $lang) {
    	global $wp_query;
    	$qv = $wp_query->query;
    	if (is_month()) {
    		$posts = get_posts(array(
    			'lang'     => $lang,
    			'year'     => $qv['year'],
    			'monthnum' => $qv['monthnum'],
    		if (empty($posts))
    			return null;
    	return $url;

    Hopefully, it will do what you expect

    Thank you for the explanation and code!

    Unfortunately, it doesn’t seems to work. I have W3 Total Cache plugin running, but I disabled it from the “General Settings”, disabling it with the “Toggle all caching types on or off (at once)” checkbox and then hit “Save”. I also tried with different browsers, cleaning their cache too.

    I’m not good with PHP, but I tried to change the function body to just “return null;” to see if I get the link to the home page always ( I guess this is what should happen, right? ) but nothing changed, in any page/post I tried.

    I also tried to spit out javascript code for debug:

    echo "<script>alert('" . $url . "');</script>";
    return null;

    It doesn’t show up any message box, although I’m VERY novice with php and coding for web in general and I’m not sure if it should do what I expect.

    Can I do something in my side to trace the problem?

    Thank you for your time.

    EDIT: I said I have the latest version of Polylang. I want to clarify that I referred to 1.1, not the development branch.

    Plugin Author Chouby


    I am sorry! I wrote this too quickly:


    add_filter('pll_language_link', 'check_archive_translation');


    add_filter('pll_the_language_link', 'check_archive_translation', 10, 2);

    Awesome! Works flawlessly!

    Thank you so much for your help!!

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Monthly archives’ is closed to new replies.