I'm using a custom php code to translate my date format on my wordpress website, using get_the_time. I have to use this code on various spaces on my website, sometimes more than one time on a page.
here is my code I'm adding inside my custom page templates when needed :
<?php
$date = get_the_time('l j F Y');
$interdit = array("Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday","Sunday","January","February","March","April","May","June","July","August","September","October","November","December");
$replace = array("Lunes", "Martes", "Miércoles", "Jueves", "Viernes", "Sábado","Domingo", "Enero","Febrero","Marzo","Abril","Mayo","Junio","Julio","Agosto","Septiembre","Octubre","Noviembre","Diciembre");
$date_espagnole = str_replace($interdit, $replace, $date);
echo ($date_espagnole);
?>
what I want to know is how can I only declare this code once, maybe in my function.php, and then just add this code when needed : <?php echo ($date_espagnole);?>
Here is what I've tried in my function.php :
function date_translation(){
$date = get_the_time('l j F Y');
$interdit = array("Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday","Sunday","January","February","March","April","May","June","July","August","September","October","November","December");
$replace = array("Lunes", "Martes", "Miércoles", "Jueves", "Viernes", "Sábado","Domingo", "Enero","Febrero","Marzo","Abril","Mayo","Junio","Julio","Agosto","Septiembre","Octubre","Noviembre","Diciembre");
$date_espagnole = str_replace($interdit, $replace, $date);
return $date_espagnole;
}
and then in my custom pages when needed : <?php date_translation();?>
but it's not working. Is it possible to do this ? and if yes, what am I doing wrong ?
thanks a lot for your help,