How to Replace the Loop with Genesis

How to Use genesis_loop to

Replace the Loop with Genesis

The Loop is a standard feature of all WordPress themes. It is responsible for fetching from the database and outputting content for single Posts and Pages, the front page, archives and search results.

With a Genesis theme, it’s easy to totally remove the Loop and replace it with any other piece of content of your choice – a widgetized front page, a slider, a video or anything. You can do this on any page of your website – the front page, single Posts and Pages, archives and even the 404 page.

Dominate Your Market with the Rainmaker Platform
This Genesis theme (Altitude Pro) replaces the Loop with a widgetized front page
Executive Pro
This Genesis theme (Executive Pro) replaces the Loop with a slider and widgetized front page

Hook

The hook to use is genesis_loop. By default, the function genesis_do_loop is hooked at the default priority 10.

Basic Code

To replace the Loop, unhook genesis_do_loop and hook your own alternative content. Below is the code.

Hint: To use a custom loop, you can use the function genesis_custom_loop.

Markup Position

Any content you hook to genesis_loop at priority 9 or less will output:

  • after the opening <main class="content"> (HTML5) or <div id="content"> (XHTML) markup element
  • after the breadcrumb trail, if breadcrumbs are turned on
  • after the archive headline on archives, if it exists
  • after the author box on author archives, if it is turned on
  • after the headline on the posts page and blog template pages
  • after the search headline on search results
  • before the close of the <main class="content"> (HTML5) or <div id="content"> (XHTML) markup element

Note that content you hook will output on every page – the front page, single Posts and Pages, archives and even the 404 page. As always, you can use conditional tags or the template hierarchy to only unhook the Loop and insert your content under certain circumstances.

Genesis Simple Hooks

If you’re a Genesis Simple Hooks user, you can find genesis_loop under Loop Hooks, enter your desired content into the box and select to unhook genesis_do_loop so that your content replaces the Loop.

Default Content

By default, genesis_do_loop is the only function hooked to genesis_loop. It is hooked at the default priority 10, via lib/structure/loops.php.

Warning!

The 404.php Genesis template uses the above method to unhook genesis_do_loopand replace it with the function genesis_404 at the default priority 10. However, your replacement content will still appear.

You can use the conditional tag is_404 to prevent your content from outputting if you don’t want it to appear on the 404 page.

Source File

The hook genesis_loop is located in lib/framework.php.

a2z Entry

Add a Comment

Your email address will not be published. Required fields are marked *