Display the Last Updated Date

Add the last updated date & time to your posts in the frontend.

Use Snippet
php
<?php
$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.
if ( $u_modified_time >= $u_time + 86400 ) {
	$updated_date = get_the_modified_time( 'F jS, Y' );
	$updated_time = get_the_modified_time( 'h:i a' );
	$updated = '<p class="last-updated">';
	$updated .= sprintf(
	// Translators: Placeholders get replaced with the date and time when the post was modified.
		esc_html__( 'Last updated on %1$s at %2$s' ),
		$updated_date,
		$updated_time
	);
	$updated .= '</p>';
	echo wp_kses_post( $updated );
}
WPCode Team
500+

Add the Page Slug to Body Class

Add the page slug to the body class for better styling.

Use Snippet
php
<?php
function wpcode_snippet_add_slug_body_class( $classes ) {
	global $post;
	if ( isset( $post ) ) {
		$classes[] = $post->post_type . '-' . $post->post_name;
	}
	return $classes;
}
add_filter( 'body_class', 'wpcode_snippet_add_slug_body_class' );
WPCode Team
300+

Add an Edit Post Link to Archives

Make it easier to edit posts when viewing archives. Or on single pages. If you...

Use Snippet
php
<?php
edit_post_link( __( '{Edit}' ) );
WPCode Team
300+

Change Excerpt Length

Update the length of the Excerpts on your website using this snippet.

Use Snippet
php
<?php
add_filter(
	'excerpt_length',
	function ( $length ) {
		// Number of words to display in the excerpt.
		return 40;
	},
	500
);
WPCode Team
200+

Change Read More Text for Excerpts

Customize the "Read More" text that shows up after excerpts.

Use Snippet
php
<?php
function wpcode_snippets_change_read_more( $read_more, $read_more_text ) {
	// Edit the line below to add your own "Read More" text.
	$custom_text = 'Read the whole post';
	$read_more = str_replace( $read_more_text, $custom_text, $read_more );
	return $read_more;
}
add_filter( 'the_content_more_link', 'wpcode_snippets_change_read_more', 15, 2 );
WPCode Team
200+

WooCommerce number of archive products per page

Change WooCommerce Archive products number per page code snippet.

Use Snippet
php
<?php
/*  Change WooCommerce Archive products number per page */
 
add_filter( 'loop_shop_per_page', 'my_new_products_per_page', 9999 );
 
function my_new_products_per_page( $pr_per_page ) {
  $pr_per_page = 16;
  return $pr_per_page;
}
Tahbit Al Bashar
<10