← Back to article index

Quick ProcessWire first child redirect snippet

From time to time it happens on a website project that you don't really have pages with teaser- or distributing-functions, but are in need for a first child redirect. In Drupal 7, for example, the most convenient solution is to install the menu_firstchild module and just juse <firstchild> in your menus.

In ProcessWire, such a quick redirect is much easier. Just use this in a template, for example _firstchildredirect.php:


/**
 * Template: First Child redirect
 *
 */

<?php
if($page->numChildren) $session->redirect($page->child()->url);

And done.