Mogul Functions

This plugin is a collection of handy functions that we’ve built and use on most of our WordPress sites.  They are intended for use by WordPress theme developers.  We’ve published them under the GPL to allow others to use them and to get feedback on any possible improvements.

Download the plugin

These functions include:


This function is core to the Mogul Functions plugin.  It quickly returns the ID number of the current page for use in other  functions.  The function does not support any arguments.

If for any reason you’d like to echo the content ID, simply put this into your script:

<?php echo mog_get_outside_id(); ?>


We use this to quickly return a link to a page using the_permalink and the_title. Typically we use this inside custom loop queries to quickly generate standard hyperlinks.

mog_quik_title($mog_quik_title_id = NULL, $noecho_quik_title = NULL);

postID refers to the post ID of any content.  In a loop, you’d normally replace this with $post->ID.  It could be substituted with mog_get_outside_id() to return a link to the current page or with a known ID number to provide a link to that page.

noecho_quik_title - defines whether the output is returned or echoed. This defaults to NULL.  If null or FALSE, the function echoes the link. If TRUE then the output will be returned for future use.

The output is in the basic format of <a href=”[permalink]“>[post_title]</a>

Example of this in use in a loop:

while ( have_posts() ) : the_post();
echo '<li>';
echo '</li>';

It’s a little on the lazy side, but our development team uses the Komodo Edit text editor, so inserting this function is much quicker than typing out a whole link structure including permalink and title for each loop.


Checks to see if the current page is in a particular hierarchy or not.  The syntax is as follows:


This will traverse the page tree from the current page (we typically use this in conjunction with mog_get_outside_id()) until it finds the comparison ID.  If none is found, the function returns FALSE meaning this page is not a descendant of the comparison ID.

This function would be used to show a particular sidebar, menu or button etc. for a given page tree (i.e. all pages nested beneath the about page).  Typical usage:

if(mog_in_hierarchy(mog_get_outside_id(),12) {
echo "This is either page 12 or a direct descendant thereof";


We use this to generate a sidebar that lists all the subpages of the top-most ancestor page for the current page.

mog_simple_sidebar($postID = NULL)

If you do not specify a postID, the function uses mog_get_outside_id() to get the current page ID.  The function then traverses the page tree upwards until it finds a page with no parent (top level) then generates and echoes a page list using wp_list_pages().


The above example might output something the looks like this:

<h3 class='widgettitle'>About</h3>
<ul class='simpleSidebar'>
<li><a href="about-sub1">About Subpage 1</a></li>
<li><a href="about-sub2">About Subpage 2</a></li>
<li><a href="about-sub3">About Subpage 3</a></li>

In future updates, we’d like the user to be able to set the classes above and to add the simple sidebar as a widget.

Download the plugin