• Resolved fakhrurpedia

    (@fakhrur)


    hello, how to fix entry meta spacing and delete some element, see this screenshoot

    i use the code snippet from elvin to show last update :

    add_filter( 'generate_post_date_output', db_modified_time_stamp, 20, 2);
    
    function db_modified_time_stamp( $output, $time_string ) {
            $time_string = '<time class="entry-date published" datetime="%1$s" itemprop="datePublished">Published on %2$s</time> ';
    
        if ( get_the_time( 'U' ) !== get_the_modified_time( 'U' ) ) {
           	$time_string = '<time class="updated" datetime="%3$s" itemprop="dateModified">Last Updated: %4$s</time> ' . $time_string;
        }
    	
    	// get modified time and published time. Compare the two, If modified date exists then ouput both time strings with modified date
    	$updated_time = get_the_modified_time( 'U' );
        $published_time = get_the_time( 'U' ) + 86400;
        
        if ( $updated_time > $published_time ) {
            $time_string = '<time class="entry-date updated-date" datetime="%3$s" itemprop="dateModified" style="display:inline;">Last Updated: %4$s</time>';
        }
    
            $time_string = sprintf( $time_string,
                esc_attr( get_the_date( 'c' ) ),
                esc_html( get_the_date('F j, Y') ),
                esc_attr( get_the_modified_date( 'c' ) ),
                esc_html( get_the_modified_date('F j, Y') )
            );
    
        $post_date = new DateTime(get_the_date( 'Y-m-d' ));
        $modified_date = new DateTime(get_the_modified_date( 'Y-m-d' ));
        $current_date = new DateTime(date('Y-m-d'));
        $published_date_interval = $post_date->diff($current_date);
        $modified_date_interval = $modified_date->diff($current_date);
    
        if ($published_date_interval->y < 2 || $modified_date_interval->y < 2 ){
          return sprintf( '<span class="posted-on">%1$s</span>', // WPCS: XSS ok, sanitization ok.
                sprintf( '%1$s',
                    $time_string
                )
          );
        } if ($published_date_interval->y >= 2 || $modified_date_interval->y >= 2 ) {
          return;
        }
    }

    The page I need help with: [log in to see the link]

Viewing 3 replies - 1 through 3 (of 3 total)
  • fernandoazarcon2

    (@fernandoazarcon2)

    Hi @fakhur,

    Try replacing your current PHP snippet with something like this:

    add_filter( 'generate_post_date_output', db_modified_time_stamp, 20, 2);
    
    function db_modified_time_stamp( $output, $time_string ) {
            $time_string = '<time class="entry-date published" datetime="%1$s" itemprop="datePublished">Published on %2$s</time> ';
    
        if ( get_the_time( 'U' ) !== get_the_modified_time( 'U' ) ) {
           	$time_string = '<time class="updated" datetime="%3$s" itemprop="dateModified">Last Updated: %4$s</time> ' . $time_string;
        }
    	
    	// get modified time and published time. Compare the two, If modified date exists then ouput both time strings with modified date
    	$updated_time = get_the_modified_time( 'U' );
        $published_time = get_the_time( 'U' ) + 86400;
        
        if ( $updated_time > $published_time ) {
            $time_string = '<time class="entry-date updated-date" datetime="%3$s" itemprop="dateModified" style="display:inline;">Last Updated: %4$s</time>';
        }
    
            $time_string = sprintf( $time_string,
                esc_attr( get_the_date( 'c' ) ),
                esc_html( get_the_date('F j Y') ),
                esc_attr( get_the_modified_date( 'c' ) ),
                esc_html( get_the_modified_date('F j Y') )
            );
    
        $post_date = new DateTime(get_the_date( 'Y-m-d' ));
        $modified_date = new DateTime(get_the_modified_date( 'Y-m-d' ));
        $current_date = new DateTime(date('Y-m-d'));
        $published_date_interval = $post_date->diff($current_date);
        $modified_date_interval = $modified_date->diff($current_date);
    
        if ($published_date_interval->y < 2 || $modified_date_interval->y < 2 ){
          return sprintf( '<span class="posted-on">%1$s </span>', // WPCS: XSS ok, sanitization ok.
                sprintf( '%1$s',
                    $time_string
                )
          );
        } if ($published_date_interval->y >= 2 || $modified_date_interval->y >= 2 ) {
          return;
        }
    }

    Hope this helps! ??

    Thread Starter fakhrurpedia

    (@fakhrur)

    thank you very much, gotcha

    fernandoazarcon2

    (@fernandoazarcon2)

    You’re welcome @fakhur! Glad that worked! ??

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Entry Meta Not Spaced’ is closed to new replies.