[Resolved] PHP in footer hook

Home Forums Support [Resolved] PHP in footer hook

Home Forums Support PHP in footer hook

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #1655102
    Lisa

    I’m using the Coach theme and am trying to insert an auto date via PHP to the footer copyright text and am not having luck. That area is a hooked element. I’ve tried inserting it directly in the existing block, created a code block and tried inline code to no avail. I’ve searched the forum and can’t find a solution. Is it possible?

    #1655236
    Elvin
    Staff
    Customer Support

    Hi there,

    I’m not exactly sure what you’re trying to achieve but consider this:

    You can control what displays as the copyright using generate_copyright filter.

    Example: add a “your text” before the copyright message.

    add_filter( 'generate_copyright', function($copyright){
    $edited_copyright = 'your text '.$copyright;
    return $edited_copyright;
    },15,1);

    Another example, say you want to apply a dynamic content like the current date after the copyright message.

    You can try this PHP snippet:

    add_filter( 'generate_copyright', function($copyright){
    $currdate = date("Y/m/d");
    $edited_copyright = $copyright.' '.$currdate;
    return $edited_copyright;
    },15,1);
    #1656150
    Lisa

    Reference site: https://poeinfo.karabinerdesign.net
    My bad for the poor initial description of the issue. I’m developing a site using the Coach theme from the GeneratePress site library. In the footer there’s an area that lets you add a copyright statement, © Your Copyright Message, but it’s added in a text block. I’m assuming using the filter above would add a section, correct?

    I wanted to add a bit of PHP to display the current year (<?php echo date(“Y”); ?>) so it would always show the current year and read, © 2021 Your Copyright Message. I can’t get it to work. I’ve tried using an HTML block and a code block, to no avail. The result always displays © <?php echo date(“Y”); ?> Chris Poe.

    I’m looking to find out if this is possible or do I need to add a separate copyright area at the very bottom.

    #1656319
    Leo
    Staff
    Customer Support

    Hi Lisa,

    You can use PHP to create a shortcode to display the current year:
    https://generatepress.com/forums/topic/footer-bar-multiple-widgets-how-to-align-them/#post-802625

    Adding PHP: https://docs.generatepress.com/article/adding-php/

    Let me know if this helps 🙂

    #1656466
    Lisa

    That worked, Leo. Thank you!

    #1656525
    Leo
    Staff
    Customer Support

    No problem 🙂

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