WPSurfer.com

GeneratePress Footer: Code Snippets

Published on July 4, 2023 | Updated on May 19, 2024

The GeneratePress theme is a lightweight and highly customizable WordPress theme designed to be fast and user-friendly.

GeneratePress is known for its clean code, responsive design, and performance.

As for the footer, in the free version of GeneratePress, the options are quite limited.

You can’t fully control the layout, style, or the number of columns without the premium version unless you start using PHP.

In this post, you will find what you need to know to customize GeneratePress Footer the way you want.



Remove Footer from GeneratePress

The code snippet removes the footer only for single posts or pages in a WordPress theme using the GeneratePress framework.

//Remove Footer
add_action('wp', 'tu_remove_header_footer');
function tu_remove_header_footer() {
    if (is_single() || is_page()) {
        remove_action('generate_footer', 'generate_construct_footer');
    }
}

If you want to remove the footer entirely from your site, you can simplify the code:

add_action('wp', 'tu_remove_header_footer');
function tu_remove_header_footer() {
    remove_action('generate_footer', 'generate_construct_footer');
}

Disable the Scroll to Top Feature

If you want to disable the “scroll to top” feature on a specific page while keeping it functional on all other pages, this is the code snippet that you have to add to your functions.php file.

add_action( 'wp', function() {
if ( 'enable' === generate_get_option( 'back_to_top' ) && is_page(1431)) {
remove_action( 'generate_after_footer', 'generate_back_to_top' );
}
}, 20 );

Change The Copyright Message

This is the code snippet you need to change the footer copyright message when you don’t have GeneratePress Premium.

Add this snippet of code to your favorite code snippets plugin.

add_filter( 'generate_copyright','tu_custom_copyright' );
function tu_custom_copyright() {
    ?>
    © 2022 - Your Custom Message
    <?php
}

This is another variation of the previous code snippet which retrieves the site name and year dynamically

//Customize Footer Message
add_filter( 'generate_copyright', 'tu_custom_copyright' );
function tu_custom_copyright() {
    $site_name = get_bloginfo( 'name' ); // Get the site name
    ?>
    © <?php echo esc_html( date( 'Y' ) ); ?> <?php echo esc_html( $site_name ); ?> • Made with Love in Costa Rica
    <?php
}

Display Content of a Post as Footer

If you don’t have GeneratePress Premium, you can use GeneratePress Hooks to insert the content of a post.

  1. Remove the footer using some of the previous code snippets.
  2. Create your footer by going to appearance>>patterns.
  3. Grab the post ID of the footer.
  4. Add the following code snippet to your site.
  5. Replace 123 with the footer post ID.
// Display Footer
function display_footer() {
    // Hardcode the post ID (replace )
    $footer_post_id = 123;
    $post = get_post($footer_post_id);
    if ($post) {
        echo apply_filters('the_content', $post->post_content);
    } else {
        echo 'Footer not found.';
    }
}
// Display Footer
function custom_footer_output() {
    if ( is_single() || is_page() ) {
        display_footer();
    }
}
add_action( 'generate_before_footer', 'custom_footer_output', 2 );

Customizing the Footer using a Child Theme

You can indeed customize the footer of your GeneratePress theme using a child theme.

A child theme allows you to make modifications to the theme without affecting the original (parent) theme files, making it easier to update the parent theme without losing your customizations.

Once you have the child theme installed and activated, grab a copy of the footer.php file and place it inside of the child theme folder.

Make the customization that you want.

You can even ask ChatGPT or Claude to:

  • Create your dream footer
  • Merge an existing footer with the footer.php file.

Manuel Campos

Manuel Campos

I am José Manuel. I am writing about things I know and things that I am learning about WordPress. I hope you find the content of this blog useful.