Okay I feel a little foolish but I just added 2001 – in front of the %1$s character and it worked.
Still would like to find some sort of explanation what those characters mean and how to know which ones to use in php.
I did try changing them to various different characters but got errors.
I’ve found a few websites that explain sprintf but don’t really go into detail on what the characters actually mean or if there is a library or list of them with their examples in use.
This explanation at stack exchange provides a little more clarity but still not enough for me to completely understand their purpose.
stack exchange
Also read through the php manual but I have a real tough time understanding anything in that manual as I believe it was written for everyone but beginners.
-
This reply was modified 4 months, 2 weeks ago by
nootkan.
-
This reply was modified 4 months, 2 weeks ago by
nootkan.
-
This reply was modified 4 months, 2 weeks ago by
nootkan.
Hi there,
sprintf is a method of injecting dynamic content inside a string of HTML.
sprintf(
'<span class=”copyright”>© %1$s %2$s</span> • %3$s',
date( 'Y' ), // phpcs:ignore
get_bloginfo( 'name' ),
__( 'All Rights Reserved', 'generatepress' ),
);
The first line contains the string:
'<span class=”copyright”>© %1$s %2$s</span> • %3$s',
the %1$s
, %2$s
and %3$s
are placeholders and will be swapped for the result of each function/value that comes after the string ie.
%1$s
swap with the value returned from date( 'Y' )
– which gets the current Year/
%2$s
swap with the value returned from get_bloginfo( 'name' )
– which gets the Site title.
%3$s
swap with the translatable string __( 'All Rights Reserved', 'generatepress' )
Hope that helps!
Awesome David, that helps a lot! Much appreciated.