Happy Halloween! Get 20% off GP Premium with the discount code: HALLOWEEN20

[Resolved] Meta in Customizer

Home Forums Support Meta in Customizer

  • This topic has 19 replies, 3 voices, and was last updated 1 year ago by Tom.
Viewing 5 posts - 16 through 20 (of 20 total)
  • Author
    Posts
  • #1047997
    Tom
    Lead Developer
    Lead Developer

    Plug this PHP into your site:

    add_filter( 'generate_header_entry_meta_items', function() {
    	return array(
    		'author',
    		'date',
    	);
    } );
    
    add_filter( 'author_link', function( $link, $author_id ) {
    	$url = get_the_author_meta( 'user_url', $author_id );
    
    	if ( $url ) {
    		$link = $url;
    	}
    
    	return $link;
    }, 10, 2 );
    
    add_filter( 'generate_post_author_output', function() {
    	return sprintf( '<span class="byline"><span class="author vcard" %5$s>%1$s <a class="url fn n" href="%2$s" title="%3$s" rel="author" itemprop="url"><span class="author-name" itemprop="name">%4$s</span></a></span></span> ',
    		__( 'Published by', 'generatepress' ),
    		esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ),
    		/* translators: 1: Author name */
    		esc_attr( sprintf( __( 'View all posts by %s', 'generatepress' ), get_the_author() ) ),
    		esc_html( get_the_author() ),
    		generate_get_microdata( 'post-author' )
    	);
    } );
    
    add_filter( 'generate_post_date_output', function( $output, $time_string ) {
        $time_string = '<time class="entry-date published" datetime="%1$s" itemprop="datePublished">%2$s</time>';
    
        if ( get_the_time( 'U' ) !== get_the_modified_time( 'U' ) ) {
            $time_string = '<time class="entry-date updated-date" datetime="%3$s" itemprop="dateModified">%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' ) )
        );
    
        return sprintf( '<span class="posted-on">Updated on %1$s at %2$s</span> ',
            $time_string,
            get_the_modified_time( 'g:i A' )
        );
    }, 10, 2 );

    Then add this CSS:

    .entry-header .entry-meta > span {
        display: block;
    }

    That should give you that exact result 🙂

    #1048014
    93487u5tr938ouh4trnos8fyoh

    Wow thank very much, that’s a lot of code. I didn’t think it require so much. So, really thanks. Do I add this in the before hook or this is site wide PHP without matter of placement?

    #1048217
    David
    Staff
    Customer Support

    Hi there,

    you would add this to either your Child Themes funtcion.php or use the code snippets plugin.

    #1048471
    93487u5tr938ouh4trnos8fyoh

    Thank you very much!

    #1048957
    Tom
    Lead Developer
    Lead Developer
Viewing 5 posts - 16 through 20 (of 20 total)
  • You must be logged in to reply to this topic.