Support » Theme: GeneratePress » Add to Copyright Filter

  • Resolved nootkan

    (@nootkan)


    Hi, I found this code in another thread in this forum and was wondering how to add to the code to show date the copyright started and the current date which is shown in the code now.

    Example: © 2001 to current date

    `add_filter( ‘generate_copyright’, function($copyright){
    $copyright = sprintf(
    ‘<span class=”copyright”>© %1$s %2$s</span> • %3$s’,
    date( ‘Y’ ), // phpcs:ignore
    get_bloginfo( ‘name’ ),
    __( ‘All Rights Reserved’, ‘generatepress’ ),
    );
    return $copyright;
    } );`

    The %2$s and other similar codes baffle me and I cannot seem to find anything that defines what they mean?

    • This topic was modified 4 months, 2 weeks ago by nootkan.
    • This topic was modified 4 months, 2 weeks ago by nootkan.
Viewing 4 replies - 1 through 4 (of 4 total)
  • Thread Starter nootkan

    (@nootkan)

    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!

    Thread Starter nootkan

    (@nootkan)

    Awesome David, that helps a lot! Much appreciated.

    You’re welcome

Viewing 4 replies - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.