Genesis Loop Actions

Posted on
5/5 - (436 votes)

When customizing Genesis, it is essential to have an understanding of what the default loop is made up of. This will help you in easily move things around with just a few lines of code.

Here’s the code from genesis/lib/structure/post.php I used to have a print-out of, next to my computer when I was a beginner:

add_action( 'genesis_entry_header', 'genesis_do_post_format_image', 4 );
add_action( 'genesis_entry_header', 'genesis_entry_header_markup_open', 5 );
add_action( 'genesis_entry_header', 'genesis_entry_header_markup_close', 15 );
add_action( 'genesis_entry_header', 'genesis_do_post_title' );
add_action( 'genesis_entry_header', 'genesis_post_info', 12 );

add_action( 'genesis_entry_content', 'genesis_do_post_image', 8 );
add_action( 'genesis_entry_content', 'genesis_do_post_content' );
add_action( 'genesis_entry_content', 'genesis_do_post_content_nav', 12 );
add_action( 'genesis_entry_content', 'genesis_do_post_permalink', 14 );

add_action( 'genesis_entry_footer', 'genesis_entry_footer_markup_open', 5 );
add_action( 'genesis_entry_footer', 'genesis_entry_footer_markup_close', 15 );
add_action( 'genesis_entry_footer', 'genesis_post_meta' );

add_action( 'genesis_after_entry', 'genesis_do_author_box_single', 8 );
add_action( 'genesis_after_entry', 'genesis_adjacent_entry_nav' );
add_action( 'genesis_after_entry', 'genesis_get_comments_template' );

A basic example of how this information can be used:

Want to move the post info from entry header and into entry footer? Just add this in your child theme’s functions.php:

remove_action( 'genesis_entry_header', 'genesis_post_info', 12 );
add_action( 'genesis_entry_footer', 'genesis_post_info' );

And for the sake of completeness, here’s the actual loop function:

/**
 * Standard loop, meant to be executed without modification in most circumstances where content needs to be displayed.
 *
 * It outputs basic wrapping HTML, but uses hooks to do most of its content output like title, content, post information
 * and comments.
 *
 * The action hooks called are:
 *
 *  - `genesis_before_entry`
 *  - `genesis_entry_header`
 *  - `genesis_before_entry_content`
 *  - `genesis_entry_content`
 *  - `genesis_after_entry_content`
 *  - `genesis_entry_footer`
 *  - `genesis_after_endwhile`
 *  - `genesis_loop_else` (only if no posts were found)
 *
 * @since 1.1.0
 *
 * @return null Return early after legacy loop if not supporting HTML5.
 */
function genesis_standard_loop() {

    // Use old loop hook structure if not supporting HTML5.
    if ( ! genesis_html5() ) {
        genesis_legacy_loop();
        return;
    }

    if ( have_posts() ) :

        do_action( 'genesis_before_while' );
        while ( have_posts() ) : the_post();

            do_action( 'genesis_before_entry' );

            printf( '<article %s>', genesis_attr( 'entry' ) );

                do_action( 'genesis_entry_header' );

                do_action( 'genesis_before_entry_content' );

                printf( '<div %s>', genesis_attr( 'entry-content' ) );
                do_action( 'genesis_entry_content' );
                echo '</div>';

                do_action( 'genesis_after_entry_content' );

                do_action( 'genesis_entry_footer' );

            echo '</article>';

            do_action( 'genesis_after_entry' );

        endwhile; // End of one post.
        do_action( 'genesis_after_endwhile' );

    else : // If no posts exist.
        do_action( 'genesis_loop_else' );
    endif; // End loop.

}

Source: genesis/lib/structure/loops.php