How To Customize Kadence Theme With Code Snippets

Here’s a concise set of code snippets to tailor the Kadence theme and its features to your needs. I’ve used Kadence on a long list of websites and found it to be a highly flexible and powerful theme. That said, some features still require adding a few code snippets to your (child) theme’s functions.php file or through a code snippets plugin to unlock their full potential.

If you’re new to Kadence or need a refresher, check out the official Kadence Documentation. It offers straightforward help articles to get you started.


Only Show Updated or Published Date on Posts, Not Both, in the Post Meta on Kadence Theme

Some SEOs and others in the industry are recommending to only show the Last Modified or Updated date in the header post meta for blog posts instead of showing both the published and last modified/updated date. I won’t get into the details of why or whether it’s necessary, but this is a common change we’re seeing by some in the industry. Kadence does not allow us to filter the post meta, but it does offer action hooks to add code after the post meta. By hiding the dates under Single Post Layout in the Customizer, we can add the code below to achieve the desired effect of one date – “Published on” date if the post has no last modified/updated date or if the last modified/updated date is less than 7 days from the Published date OR “Updated on” date if the post has been updated more than 7 days after the original published date.

/* Important Note: Be sure to turn off dates in Single Post Layout in the Customizer for this to make sense. You cannot rearrange the other post meta due to Kadence limitations without further custom coding. */
add_action('kadence_after_entry_meta','custom_post_dates');
function custom_post_dates(){
 $date = get_the_time( 'U' );
 $updated = get_the_modified_time( 'U' );
 $time_string = '<span class="posted-on"><span class="meta-label">Published on</span><time class="entry-date published updated" datetime="%1$s">%2$s</time>';
 if ( $date !== $updated && $updated > ($date + WEEK_IN_SECONDS)) {
  $time_string = '<span class="updated-on"><span class="meta-label">Updated on</span><time class="updated" datetime="%3$s">%4$s</time>';
 }
 $time_string = sprintf(
  $time_string,
  esc_attr( get_the_date( 'c' ) ),
  esc_html( get_the_date() ),
  esc_attr( get_the_modified_date( 'c' ) ),
  esc_html( get_the_modified_date() )
 );
 if(! empty($time_string)){
  echo $time_string . '</span>';
 }
}

Leave your ideas, requests, or feedback on these code snippets below in the comments. Thanks!

Leave a Comment