Title: Adding new functions, general_template.php page
Last modified: August 19, 2016

---

# Adding new functions, general_template.php page

 *  [jami1955](https://wordpress.org/support/users/jami1955/)
 * (@jami1955)
 * [17 years, 4 months ago](https://wordpress.org/support/topic/adding-new-functions-general_templatephp-page/)
 * Hi,
    first, wordpress forums is very helpful, I have found answers to ALL of 
   my questions within 24 hours here. wow.
 * In the previous version 2.6, in order to add a function, like for instance to
   have a template page call a different sidebar, all I had to do was define the
   new sidebar in the general_template.php page and presto, I got my new template
   page to call it’s own special sidebar.
 * I tried with version 2.7, and found the process of defining functions is spread
   all over the place and I can’t figure out how to define anything new. Here is
   the code in general_template.php for calling the sidebar:
 *     ```
       function get_sidebar( $name = null ) {
       	do_action( 'get_sidebar' );
   
       	$templates = array();
       	if ( isset($name) )
       		$templates[] = "sidebar-{$name}.php";
   
       	$templates[] = "sidebar.php";
   
       	if ('' == locate_template($templates, true))
       		load_template( get_theme_root() . '/default/sidebar.php');
       }
       ```
   
 * Can I change this code to get a new sidebar defined? Or if not, where and how
   do I do that?
 * thanks,
    JSC

Viewing 8 replies - 1 through 8 (of 8 total)

 *  [vomers](https://wordpress.org/support/users/vomers/)
 * (@vomers)
 * [17 years, 4 months ago](https://wordpress.org/support/topic/adding-new-functions-general_templatephp-page/#post-960543)
 * The function is set up to allow for multiple sidebar configurations.
 * just call the function with the name of your sidebar
    <?php get_sidebar(name);?
   >
 * For example if I wanted do add a sidebar on the right side I would
    create the
   sidebar file and name the file sidebar-right.php
 * I could name it sidebar-blue.php and still have it show up on the right side 
   it is just the name used to locate the file that displays the sidebar.
 * then just call the function
    <?php get_sidebar(right); ?>
 * and it will use the sidebar-right.php
 * file for the sidebar
 * I hope that helps.
 *  Thread Starter [jami1955](https://wordpress.org/support/users/jami1955/)
 * (@jami1955)
 * [17 years, 4 months ago](https://wordpress.org/support/topic/adding-new-functions-general_templatephp-page/#post-960587)
 * Thanks! we’re getting there, so to clarify:
    If I create a sidebar page called
   sidebar-02.php and want that to be called on my template page, do I call the 
   function <?php get_sidebar(02); ?> ?
 * What’s a little confusing is that in my theme (cognoblue) the original sidebar
   that is called with this function is sidebar_r.php which is written with an underscore,
   not a hyphen… but if I have what you’re saying correct, I’ll try it.
 * thanks again,
    JSC
 *  Moderator [Samuel Wood (Otto)](https://wordpress.org/support/users/otto42/)
 * (@otto42)
 * WordPress.org Admin
 * [17 years, 4 months ago](https://wordpress.org/support/topic/adding-new-functions-general_templatephp-page/#post-960590)
 * The correct syntax would actually be:
 *     ```
       <?php get_sidebar('02'); ?>
       <?php get_sidebar('right'); ?>
       ```
   
 * The quotes make it a string. I know, pedantic, but it sometimes makes a difference.
 * As far as the underscore/hyphen.. Rename the existing file to use a hyphen instead.
 *  [jamie1955](https://wordpress.org/support/users/jamie1955/)
 * (@jamie1955)
 * [17 years, 4 months ago](https://wordpress.org/support/topic/adding-new-functions-general_templatephp-page/#post-960621)
 * Right, that helped! thanks.
 * What I did was this: the original code was
    `<?php include(TEMPLATEPATH."/sidebar_r.
   php");?>` which still works on several templates, and I added this
 * `<?php include(TEMPLATEPATH."/sidebar-authors.php");?>`
    to put my special sidebar
   on my authors’ page. works great, much simpler than the other way of going into
   general_template.php and adding functions! great stuff. JSC
 *  Moderator [Samuel Wood (Otto)](https://wordpress.org/support/users/otto42/)
 * (@otto42)
 * WordPress.org Admin
 * [17 years, 4 months ago](https://wordpress.org/support/topic/adding-new-functions-general_templatephp-page/#post-960634)
 * While a direct include will indeed work, using something like this:
    `<?php get_sidebar('
   authors'); ?>` is safer and better. It does essentially the same thing, but with
   the benefit of being inside a function scope, as well as having the ability to
   fallback to the sidebar.php if the sidebar-authors.php file is missing.
 *  [jamie1955](https://wordpress.org/support/users/jamie1955/)
 * (@jamie1955)
 * [17 years, 4 months ago](https://wordpress.org/support/topic/adding-new-functions-general_templatephp-page/#post-960646)
 * Here’s an interesting question: now that I’ve got my authors page calling my 
   special sidebar…. how do I get that special sidebar to show up in the drop down
   sidebar list in my admin widgets control panel, so that I can configure that 
   sidebar differently than the original one?
 *  [jamie1955](https://wordpress.org/support/users/jamie1955/)
 * (@jamie1955)
 * [17 years, 4 months ago](https://wordpress.org/support/topic/adding-new-functions-general_templatephp-page/#post-960648)
 * Actually Otto42, I changed the code to what you suggested
    <?php get_sidebar(‘
   authors’); ?> but that rendered this call for the author’s thumbnail pic in the
   sidebar which comes from the [user-photo plugin](http://wordpress.org/extend/plugins/user-photo/)
   useless. The picture would not show up anymore. The code `<?php userphoto_thumbnail(
   $authordata) ?>` only works in that sidebar when it is called like this `<?php
   include(TEMPLATEPATH."/sidebar-authors.php");?>` C’est la code…
 * thanks for your help
    JSC
 *  Moderator [Samuel Wood (Otto)](https://wordpress.org/support/users/otto42/)
 * (@otto42)
 * WordPress.org Admin
 * [17 years, 4 months ago](https://wordpress.org/support/topic/adding-new-functions-general_templatephp-page/#post-960650)
 * Do this instead:
 *     ```
       <?php
       global $authordata;
       userphoto_thumbnail($authordata);
       ?>
       ```
   
 * That will prevent the issue you saw.

Viewing 8 replies - 1 through 8 (of 8 total)

The topic ‘Adding new functions, general_template.php page’ is closed to new replies.

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 8 replies
 * 4 participants
 * Last reply from: [Samuel Wood (Otto)](https://wordpress.org/support/users/otto42/)
 * Last activity: [17 years, 4 months ago](https://wordpress.org/support/topic/adding-new-functions-general_templatephp-page/#post-960650)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
