Easy Way To Displaying The Article Update In WordPress

Are you blogging on WordPress and have been doing so for a while? Then you might have an inkling that some of your articles are outdated and need an update. Unfortunately, WordPress doesn’t inherently account for this, displaying only the date of the article’s initial publication. This could be counterproductive when a potential reader stumbles upon such an article and leaves the website, assuming it’s not current based on the date. That’s why it’s a good practice to show the date of the article’s last update as well. Why? Because it lets the reader know the article isn’t outdated and that you regularly keep it fresh. Easy way to displaying the article update in WordPress. So, if you don’t want to needlessly lose users from your site, display the date of the article’s last modification in WordPress. It’s easy.

Easy Way To Displaying The Article Update In WordPress

To avoid installing an additional plugin for these purposes, we’ll use a snippet and the popular WPCode plugin, which should be installed by anyone looking to modify the properties and behavior of their WordPress website. A snippet is nothing more than a short piece of code in PHP or another language that alters the properties and behavior of the website.

Installing the WPCode plugin

To insert codes into your website, you have two options. You can hardcode the code into the file where it belongs, or you can use a plugin that will insert parts of the code into the website during its operation. The second option is better for a simple reason: it’s safer and ensures your code doesn’t get wiped out with each update that overwrites the file containing your code.

To install the WPCode plugin, follow these steps:

  • Click on “Plugins” in the left menu.
  • Select “Add New” in the submenu.
  • Notice the search bar in the top right corner.
  • Type in the keyword “WPCode.”
  • Once WordPress finds the plugin, install and activate it.

If you’re interested in the complete article where I describe working with this plugin, take a look here: How to insert custom codes into WordPress

Jak do WordPressu vkládat vlastní kódy

Easy Way To Displaying The Article Update In WordPress using snippet

To display the date of the last modification in your article, use the snippet provided below. Insert this snippet into your website and in the WPCode plugin, choose “insert before paragraph” as the placement. The date will then appear below the main image of the article along with the author’s name.

Let’s explore two versions of this snippet. The first version is for a single-language website in Czech. The second version is for websites using the PolyLang plugin and are multilingual. In the second version, we work with the display of information in another language. We’ll illustrate this with an example of a website in Czech and English. I’ve chosen a 24-hour format in the snippet since Czechs don’t use AM and PM. Additionally, I’ve modified the snippet to display the information only within articles, not on the website’s pages.

Snippet for a single-language website in Czech:

				
					// Check if it's a single post and display modified date if 24hrs have passed since the post was published.
if ( is_single() ) {
    $u_time          = get_the_time( 'U' );
    $u_modified_time = get_the_modified_time( 'U' );

    if ( $u_modified_time >= $u_time + 86400 ) {
     
        $updated_date = get_the_modified_time( 'j. F Y' ); // Zkrácený formát českého data
        $updated_time = get_the_modified_time( 'H:i' ); // 24-hodinový formát bez AM/PM
     
        $updated = '<p class="last-updated">';
     
        $updated .= sprintf(
            __( 'Naposledy upraveno %1$s v %2$s' ),
            $updated_date,
            $updated_time
        );
        $updated .= '</p>';
     
        echo wp_kses_post( $updated );
    }
}
				
			

Snippet for a single-language website in English:

				
					// Check if it's a single post and display modified date if 24hrs have passed since the post was published.
if ( is_single() ) {
    $u_time          = get_the_time( 'U' );
    $u_modified_time = get_the_modified_time( 'U' );

    if ( $u_modified_time >= $u_time + 86400 ) {

        $updated_date = get_the_modified_time( 'F j, Y' ); // Full English date format
        $updated_time = get_the_modified_time( 'g:i A' ); // 12-hour format with AM/PM

        $updated = '<p class="last-updated">';

        $updated .= sprintf(
            __( 'Last updated on %1$s at %2$s' ),
            $updated_date,
            $updated_time
        );
        $updated .= '</p>';

        echo wp_kses_post( $updated );
    }
}

				
			

Snippet for a multilingual website – Czech and English

				
					$u_time          = get_the_time( 'U' );
$u_modified_time = get_the_modified_time( 'U' );

// Only display modified date if 24hrs have passed since the post was published and it's a post, not a page.
if ( is_single() && $u_modified_time >= $u_time + 86400 ) {
    $updated_date = get_the_modified_time( 'F jS, Y' );
    
    $updated_time = get_the_modified_time( 'H:i' ); // 24-hour format without AM/PM

    $updated = '<p class="last-updated">';
    
    if ( function_exists( 'pll_current_language' ) ) {
        $current_language = pll_current_language(); // Get current language
        if ( $current_language === 'cs' ) {
            // For Czech language
            $updated .= sprintf(
                esc_html__( 'Upraveno %1$s %2$s', ),
                $updated_date,
                $updated_time
            );
        } elseif ( $current_language === 'en' ) {
            // For English language
            $updated .= sprintf(
                esc_html__( 'Last updated %1$s %2$s' ),
                $updated_date,
                $updated_time
            );
        }
    } else {
        // Default fallback if Polylang is not active
        $updated .= sprintf(
            esc_html__( 'Last updated %1$s %2$s', 'text-domain' ),
            $updated_date,
            $updated_time
        );
    }

    $updated .= '</p>';

    echo wp_kses_post( $updated );
}
				
			

Easy Way To Displaying The Article Update In WordPress

Conclusion

You now have a choice between two snippets: one for a single-language website and one for a multilingual site. You can adjust the placement of this information by using the WPCode plugin. By displaying the last update of your article’s content, you’re showing users that you regularly maintain your content, which can help you maintain higher viewership numbers. The actual insertion of the code into your website takes a maximum of two minutes. Definitely give it a try.

The website is created with care for the included information. I strive to provide high-quality and useful content that helps or inspires others. If you are satisfied with my work and would like to support me, you can do so through simple options.

Byl pro Vás tento článek užitečný?

Klikni na počet hvězd pro hlasování.

Průměrné hodnocení. 0 / 5. Počet hlasování: 0

Zatím nehodnoceno! Buďte první

Jak užitečný vidíte tento článek.

Sledujte mě na sociálních médiích.

Je mi líto, že pro Vás nebyl článek užitečný.

Jak mohu vylepšit článek?

Řekněte mi, jak jej mohu zlepšit.

newsletter

Subscribe to the Newsletter

Stay informed! Join our newsletter subscription and be the first to receive the latest information directly to your email inbox. Follow updates, exclusive events, and inspiring content, all delivered straight to your email.

Odebírat
Upozornit na
guest
0 Komentáře/ů
Vložené zpětné vazby.
Zobrazit všechny komentáře.

Pokud mi chcete napsat rychlou zprávu, využije, prosím, níže uvedený
kontaktní formulář. Děkuji.

Další Kontaktní údaje