[Resolved] Related posts show wrong date format

This topic contains 5 replies, has 2 voices, and was last updated by  Andrew Misplon 6 months, 1 week ago.

  • Author
    Posts
  • #8688

    Birgit
    Participant

    Dear Support,

    as mentioned in my first support post, I have another problem with the Polestar theme. This is related to the date format of the related posts that show at the bottom of my blog page. I am using the plugin The Post Grid to display the posts as a grid, so I am not sure whether the problem might originate from the plugin.

    Anyway, when you select a post from the blog grid and scroll to the end of the single-post page, you see the related posts with the American date format (month day, year) and not, as specified in my general settings of the theme, in the German format (day. month year). Since I translated the title of the related-posts section in the theme folder (using Loco Translate), I suspect that the problem lies somewhere in the theme files. Please advise where I should be searching to correct the date format.

    By the way: Another plugin for popular posts, The Top 10, displays the date in the correct format, if I enable this function. So maybe the culprit is the grid plugin after all?

    Any help would be greatly appreciated.

    Kind regards,

    Birgit

    #8696

    Andrew Misplon
    Keymaster

    Hi Birgit

    Thanks for posting. I’ll correct this in the next update. For now, the date is available in a filter. So you can do this:

    If you aren’t using a child theme:
    Go to plugins, install and activate Code Snippets. Add a new snippet. Name it as you’d like. In the snippet body add:

    function polestar_child_related_posts() {
      return get_the_date();
    }
    add_filter( 'polestar_date_format', 'polestar_child_related_posts' );

    Select the option to run the snippet on the site front end. Save changes and activate. Not just save changes. Save and activate.

    If you are using a child theme then insert the above function in your child functions.php file. Both can be removed after the next theme update 🙂

    #8701

    Birgit
    Participant

    Hi Andrew,

    thanks for getting back to me so quickly.

    I am using a child theme, but since I have no clue about php (I pick up bits and pieces from the Internet, if I need to), I have added the code using the code snippet plugin in the child theme. It changes the date to something like this:

    Mon,52016000Europe/Berlin11bEurope/BerlinFri,11 Nov 2016 09:19:44 +0000 2016

    If I change the middle line to “return the_date (‘j. F Y’);”, it gives me this:

    11. November 20169:19

    This is nice, but still not quite what I want. Is there a way to get rid of the time?

    Cheers,

    Birgit

    #8704

    Andrew Misplon
    Keymaster

    It’s best not to use a child theme and Code Snippets. You can but there is a bit of functionality double up then. Ideally just insert the function I sent into your child theme functions.php file.

    Sorry, please, change the entire function to:

    function polestar_child_date_format() {
      return 'j, F Y';
    }
    add_filter( 'polestar_date_format', 'polestar_child_date_format' );
    #8716

    Birgit
    Participant

    Hi Andrew,

    argh. I have uninstalled the Code Snippets plugin now and fiddled around with the functions.php file. I had to search for how I create one for a child theme first and now have one that looks like this:
    ________________
    <?php

    /**
    * Enqueue theme scripts and styles.
    */
    function polestar_child_scripts() {

    // Child theme stylesheet.
    wp_enqueue_style( ‘polestar-child’, get_stylesheet_directory_uri() . ‘/style.css’ );

    }
    add_action( ‘wp_enqueue_scripts’, ‘polestar_child_scripts’, 8 );

    function polestar_child_date_format() {
    return ‘j. F Y’;
    }
    add_filter( ‘polestar_date_format’, ‘polestar_child_date_format’ );

    ?>
    _________

    The first part is from my other support post, in which you pointed me to the enqueue bit. Does this file look alright? It seems to work properly. At least the dates are correct now, so this problem seems to be sorted.

    Thank you very much.

    Kind regards,

    Birgit

    #8717

    Andrew Misplon
    Keymaster

    Looks good 🙂

Viewing 6 posts - 1 through 6 (of 6 total)

You must be logged in to reply to this topic.

Scroll to top