• Resolved psonetz

    (@psonetz)


    Hi,
    how can I reach that last modified date is shown in post meta after the publishing date?

Viewing 6 replies - 1 through 6 (of 6 total)
  • Theme Author Anders Norén

    (@anlino)

    Hi @psonetz,

    I’ve been meaning to make it easier to modify the post meta output in Chaplin for a while, and your question nudged me to get around to it, so kudos for that. When you’ve updated to version 2.4.0 of Chaplin, which should be live in a bit, you’ll be able to add the modified date to the post meta by adding the code below to the functions.php file in a child theme:

    // Post meta: Add the modified_date post meta item to the end of the single top and archive post meta
    function chaplin_child_post_meta_add_modified_date( $post_meta ) {
    
    	$post_meta[] = 'post-date-modified';
    
    	return $post_meta;
    
    }
    add_filter( 'chaplin_post_meta_items_single-top', 'chaplin_child_post_meta_add_modified_date' );
    add_filter( 'chaplin_post_meta_items_archive', 'chaplin_child_post_meta_add_modified_date' );
    
    // Post meta: Output the modified_date post meta item
    function chaplin_child_post_meta_output_modified_date( $post_id, $location ) {
    	global $has_meta;
    	$has_meta = true;
    	?>
    	<li class="post-date">
    		<a class="meta-wrapper" href="<?php the_permalink(); ?>">
    			<span class="meta-icon">
    				<span class="screen-reader-text"><?php esc_html_e( 'Post modified date', 'chaplin-child' ); ?></span>
    				<?php chaplin_the_theme_svg( 'calendar' ); ?>
    			</span>
    			<span class="meta-text">
    				<?php printf( __( 'Updated %s', 'chaplin-child' ), get_the_modified_date( get_option( 'date_format' ) ) ); ?>
    			</span>
    		</a>
    	</li>
    	<?php
    }
    add_action( 'chaplin_post_meta_post-date-modified', 'chaplin_child_post_meta_output_modified_date', 10, 3 );

    Let me know if it works as expected.

    — Anders

    Thread Starter psonetz

    (@psonetz)

    Great, it works, thanks! ??

    +1

    Thread Starter psonetz

    (@psonetz)

    Hi Anders,
    could it be that your solution doesn’t work with 2.4.2?

    Theme Author Anders Norén

    (@anlino)

    Hi @psonetz,

    Yes, sorry about that – I tweaked the filter structure slightly. I can’t edit the reply anymore, so I’ve posted the updated code for the first function below.

    // Post meta: Add the modified_date post meta item to the end of the single top and archive post meta
    function chaplin_child_post_meta_add_modified_date( $post_meta, $location ) {
    	
    	if ( in_array( $location, array( 'archive', 'single-top' ) ) ) {
    		$post_meta[] = 'post-date-modified';
    	}
    
    	return $post_meta;
    
    }
    add_filter( 'chaplin_post_meta_items', 'chaplin_child_post_meta_add_modified_date', 10, 2 );

    — Anders

    Thread Starter psonetz

    (@psonetz)

    Many thanks, it works.

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Last modified date in post meta’ is closed to new replies.