Site logo

Archived topic

Post date below the author's name

14 replies · Started by Roger on June 19, 2022

Viewing posts 1–15 of 15

Hello,

How to keep the post date below the author's name?

I prefer to make these adjustments with code, without using GenerateBlocks.

I see. To clarify, may I know how you added the author image? I’ll modify the code.

Kindly enclose the code in a code block: https://share.getcloudapp.com/qGuOloDR

Hope to hear from you soon.

`// Author photo
add_filter( ‘generate_post_author_output’, function( $output ) {
$avatar = get_avatar( get_the_author_meta( ‘ID’ ) );

if ( $avatar ) {
return $avatar . $output;
}

return $output;
} );

// Author and Date
add_filter( ‘generate_header_entry_meta_items’, function() {
return array(
‘author’,
‘date’,
);
} );

Thank for adding the code. You may first alter it to something like this:

add_filter( 'generate_post_author_output', function( $output ) {
	$avatar = get_avatar( get_the_author_meta( 'ID' ) );
	if(is_single()){
		if ( $avatar ) {
			return $avatar . '<div class="my-inner-meta">' . $output;
		}
		return '<div class="my-inner-meta>' . $output;
	}
	return $output;
} );
	

add_filter( 'generate_header_entry_meta_items', function() {
	return array(
	'author',
	'date',
	);
} );

add_filter('generate_post_date_output', function($output){
	if(is_single()){
		return $output . '</div>';
	}
	return $output;
});

Kindly let us know once you’ve modified it, and I’ll take a look what CSS is needed to set the layout to your preference.

Side note, here’s a screen recording with regards to using the code block: https://share.getcloudapp.com/6quzxBbx

Copying and pasting without using the code block makes the quotation marks slanted which causes syntax errors.

This code reported an error:

The changes to your PHP code were undone due to an error on line 193 of the wp-content/themes/generatepress/functions.php file.

Please correct and try saving again.

syntax error, unexpected '>'

add_filter( 'generate_post_author_output', function( $output ) {
	$avatar = get_avatar( get_the_author_meta( 'ID' ) );
	
	if ( $avatar ) {
	return $avatar . '<div class=“my-inner-meta”>’ . $output;
	}
	
	return '<div>' . $output;
	} );

Can you test the code above again? Sorry, there was a slanted quotation mark i missed to replace with a straight one.

Kindly let us know how it goes.

The meta links have been moved under the author's photo.
My purpose is for them to be aligned in front of the photo (see the link)

For some reason this code is changing the layout of the categories feed.

add_filter('generate_post_date_output', function($output){
		return $output . '</div>';
});

Thank you for modifying the code.

Yes, the PHP code was just the first step.

Now, kindly try adding this CSS in Appearance > Customize > Additional CSS:

.post header.entry-header > .entry-meta {
    display: flex;
}

.my-inner-meta {
    display: flex;
    flex-direction: column;
    margin-left: 5px;
}

Kindly let us know how it goes.

With regards to the PHP, I modified the code above once more so it only works for single posts. Kindly try it out once more and see how it goes.

Thanks for the support and great work!

It worked!

You’re welcome Roger! Glad that worked!

This archived topic is closed to new replies.