Site logo

Archived topic

Insertar fecha y hora de creación en las entradas

5 replies · Started by Joaquín on January 4, 2022

Viewing posts 1–6 of 6

Buenas noches,

En mi wordpress, he configurado en Ajustes --> Generales:

- Fecha con este formato: 5 de enero de 2022j \d\e F \d\e Y
- Hora con este formato: 02:30H:i

Sin embargo, cuando consulto la página web, solo me aparece la fecha y nunca la hora.

¿Qué puedo estar haciendo mal?

Por otra parte, me gustaría que la fecha apareciera debajo de la imagen destacada... tampoco veo donde se configura :(

Gracias por el apoyo!

Hi Joaquín,

Can you type in the desired date format sample you want?

Example: 5th of January 2022, 02:30 PM

So we can help you out with the date formatting syntax.

Let us know. :D

Hola Elvin,

La fecha que quiero poner es "5 de enero de 2022, 22:45"

Por favor, le ruego que en caso de que tuviera que insertar código fuente en algún sitio me especificara con detalle donde sería.

Saludos y gracias,

Joaquín.

Ah I see.

You're trying to display the date meta like this? https://share.getcloudapp.com/mXuJ7o1O

If so, you don't have to bother w/ the Time format.

Just place this entire string - j \d\e F \d\e Y, H:i - inside the Date format on Settings > General. It should display the time on the date meta.

Alternatively, you can go with PHP snippet like this:

add_filter( 'generate_post_date_output', 'tu_show_modified_date' );
function tu_show_modified_date() {
	$time_string = '<time class="entry-date published" datetime="%1$s" itemprop="datePublished">%2$s</time>';
	
	if ( $updated_time > $published_time ) {
		if ( apply_filters( 'generate_post_date_show_updated_only', false ) ) {
			$time_string = '<time class="entry-date updated-date" datetime="%3$s"%6$s>%4$s</time>';
		} else {
			$time_string = '<time class="updated" datetime="%3$s"%6$s>%4$s</time>' . $time_string;
		}
	}

	$time_string = sprintf( $time_string,
		esc_attr( get_the_date() ),
		esc_html( get_the_date('j \d\e F \d\e Y, H:i') ),
		esc_attr( get_the_modified_date() ),
		esc_html( get_the_modified_date('j \d\e F \d\e Y, H:i') ),
		'microdata' === $schema_type ? ' itemprop="datePublished"' : '',
		'microdata' === $schema_type ? ' itemprop="dateModified"' : ''
	);
	
	printf( '<span class="posted-on">%1$s</span>', // WPCS: XSS ok, sanitization ok.
			$time_string
	);
}

Resuelto amigo! Muchísimas gracias!

No problem. :D

This archived topic is closed to new replies.