Best WordPress functions – To Start WordPress Theme Development

WordPress themes come in default and are also developed with new implementations. Before using these themes one must know everything about WordPress functions that go on to develop the themes. There are a wide range of functionalities that need to be known to move forward with the development processes. Needs for projects must be known to develop functions. There are some common WordPress functions that meet the requirement of theme developments.

Custom avatar

Bloggers and people posting comments on blogs usually have online avatars. Default avatars are available and customized avatar designs can be defined as well. In order to make a function work one must check whether the function exists. Wherever a function exists a filter is added in WordPress to implement a custom avatar instead of an existing default avatar. WordPress is asked to find the custom avatar in the images directory that resides within the theme directory. The last step is to create the image and upload it in “images” folder. The codes provided below must be included in functions.php in order to acquire accustom avatar:

if ( !function_exists(‘cake_addgravatar’) ) {
function cake_addgravatar( $avatar_defaults ) {
$myavatar = get_template_directory_uri() . ‘/images/avatar.png’;
$avatar_defaults[$myavatar] = ‘avatar’;
return $avatar_defaults;
}
add_filter( ‘avatar_defaults’, ‘cake_addgravatar’ );
}


Custom menu

Navigation menus can be created in WordPress themes with the help of the navigation menu feature which has been introduced in WordPress 3.0. A lot of variation can be brought about with the custom menu. There will be a need for two menus such as “Main Menu” and “Secondary Menu”. In order to get a standard theme it is important to refer to a main navigation menu. Codes mentioned below must be included in the functions.php file:

if ( function_exists( ‘register_nav_menus’ ) ) {
register_nav_menus(
array(
‘main_menu’ => __( ‘Main Menu’, ‘cake’ ),
‘secondary_menu’ => __( ‘Secondary Menu’, ‘cake’ ),
)
);
}

Soon after menus are registered the theme needs to be provided a command to bring out the output in a specific place. In order to show the main menu in the header codes provided below must be included in the header.php file.

< !–?php if ( has_nav_menu( ‘main_menu’ ) ) { ?– >
< !–?php $defaults = array( ‘theme_location’ =–> ‘main_menu’,
‘menu’ => ”,
‘container’ => false,
‘echo’ => true,
‘fallback_cb’ => false,
‘items_wrap’ => ‘< ul id=”%1$s”>%3$s < /ul >’,
‘depth’ => 0 );
wp_nav_menu( $defaults );
?>
< ?php } else { ? >
< ul >
< ?php wp_list_pages(‘title_li=’); ? >
< /ul >
< ?php }? >

First step is to check whether the main menu is rightly defined. The next step is to insert the content in here. Not following this step would take an individual back to the default wp_list_pages(). These can be customized to bring out and display the links as and where required. In order to implement better customizations in the menu WordPress codex page with wp_nav_menu functions must be checked before implementing the changes.

In order to make the secondary menu appear in the footer section codes need to be included in the footer.php. Following are the codes required for inclusion in footer.php:

< ?php if ( has_nav_menu( ‘secondary_menu’ ) ) { ? >
< ?php $defaults = array( ‘theme_location’ => ‘secondary_menu’,
‘menu’ => ”,
‘container’ => false,
‘echo’ => true,
‘fallback_cb’ => false,
‘items_wrap’ => ‘ < ul id=”%1$s”>%3$s< /ul >’,
‘depth’ => 0 );
wp_nav_menu( $defaults );
?>
< ?php } else {? >
< ul >
< ?php wp_list_pages(‘title_li=’); ? >
< /ul >
< ?php }? >


Featured image function

In order to bring changes and include representative images in Pages, Custom Post Types and Posts the featured image function comes in handy. In order to activate this function the code provided below must be included in functions.php:

add_theme_support( ‘post-thumbnails’ );

WordPress is able to include definitions all by itself. But if one needs to make the changes by themselves then there are options open to handle controls and other functions in defining featured images.

add_image_size() function helps in copying a featured image in defined sizes (sizes defined by users to make them appear on various posts in different sizes.) In order to achieve this functionality the following codes need to be added in functions.php:

// regular size
add_image_size( ‘regular’, 400, 350, true );

// medium size
add_image_size( ‘medium’, 650, 500, true );

// large thumbnails
add_image_size( ‘large’, 960, ” );


Post

Post formats is a function that allows WordPress to bring in advanced customizations in post styles and presentations. There are 9 standard post formats such as quote, aside, chat, gallery, link, audio, image, video and status. In order to achieve the function in posts the following set of codes need to be included in functions.php:

add_theme_support( ‘post-formats’, array( ‘aside’, ‘image’, ‘link’, ‘quote’, ‘status’ ) );

This will allow inclusion of functionality in your existing WordPress theme. Specifying individual post formats will let you achieve your desired format for posts.

WordPress is the best designing, structuring and content presentation platform that is able to achieve high standards with the help of customizations.

09 Apr 2013

Augment Your Web and Graphic Design Skills with Adobe InDesign

Technology has made a great impact on different life aspects and is…

14 Jan 2014

Free HTML5 Theme for Beauty Site in Radiant Orchid –…

The year 2014 is going to be energetic, captivating and a bit…

Written by

Allison Reed

Allison is a professional SEO specialist and an inspired author. Marketing manager by day and a writer by night, she is creating many articles on business, marketing, design, and web development. Follow her on LinkedIn and Facebook.

Post Comment

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

Managed by Quantum VXenon