how to create menu in wordpress themes

From wordpress 3.0 release wordpress launched the custom navigation Menu in wordpress admin panel. wordpress tutorial for, how to create menu in wordpress themes. Through drag and drop you can manage the menus. Using this menus are very easy for users.

how to create menu in wordpress themes

how to create menu in wordpress themes
how to create menu in wordpress themes

You can check wordpress admin section for managing the menus in wordpress theme.

In this article I will show you how to enable Custom menu for your wordpress theme.

If you want to create the one menu in wordpress theme then just open the functions.php file and put following code in that file.


add_theme_support( 'menus' );

If you want to create or use the multiple menus in wordpress theme then just open the functions.php file and put following code in that file.


add_action( 'init', 'register_my_menus' );

function register_my_menus() {
 register_nav_menus(
 array(
 'primary-menu' => __( 'Main Menu' ),
 'secondary-menu' => __( 'Top Menu' ),
 'tertiary-menu' => __( 'Footer Menu' )
 )
 );
}

After this adding code in functions.php file you need to open the header.php and footer.php file.

For single menu you need to add following code in header.php file.


<?php wp_nav_menu( array( 'sort_column' => 'menu_order', 'container_class' => 'menu-header' ) ); ?>

For multiple menu you need to add following code in header.php or footer.php file

# Following code for Top Menu


wp_nav_menu( array( 'theme_location' => 'secondary-menu', 'sort_column' => 'menu_order', 'container_class' => 'nav' ) );

#Following code for Main Menu


&lt;?php wp_nav_menu( array( 'theme_location' => 'primary-menu', 'sort_column' => 'menu_order', 'container_class' => 'nav' ) ); ?>

#Following code for Footer Menu


&lt;?php wp_nav_menu( array( 'theme_location' => 'tertiary-menu' ) ); ?>

Above code will give you the more control over the wordpress theme. If you have any doubts or questions then please do write to me.

Remove author word from wordpress permalink

In wordpress some people wants to create the community site and they want to create uniqe url for each user. In that time you need to remove the author word from wordpress permalink. Normally when we want to see the author URL then you can see URL as follows.

Remove author word from wordpress permalink

Co-Authors Plus Remove author word from wordpress permalink
Co-Authors Plus Remove author word from wordpress permalink

http://website.com/author/username/

If you can want to change the url to following

http://website.com/username

then you just need to edit only .htaccess file. Put following line in that file

RewriteRule ^author/(.+)$ http://www.yourblog.com/$1 [R=301,L] // change yourblog to website name 

If you dont want to change the .htaccess file and still want to change the permalink structure then open the functions.php file from you wordpress theme folder.

add_filter('author_link', 'no_author_base', 1000, 2);
function no_author_base($link, $author_id) {
    $link_base = trailingslashit(get_option('home'));
    $link = preg_replace("|^{$link_base}author/|", '', $link);
    return $link_base . $link;
}
add_filter('author_rewrite_rules', 'no_author_base_rewrite_rules');
function no_author_base_rewrite_rules($author_rewrite) {
    global $wpdb;
    $author_rewrite = array();
    $authors = $wpdb->get_results("SELECT user_nicename AS nicename from $wpdb->users");
    foreach($authors as $author) {
        $author_rewrite["({$author->nicename})/page/?([0-9]+)/?$"] = 'index.php?author_name=$matches[1]&paged=$matches[2]';
        $author_rewrite["({$author->nicename})/?$"] = 'index.php?author_name=$matches[1]';
    }
    return $author_rewrite;
}

How to put digg button in wordpress without plugin

Recently digg launched the version 4 and many people want to put digg button on there wordpress sites and blogs. There are many wordpress plugins available for putting digg button on wordpress.

How to put digg button in wordpress without plugin

But I cannot recommend to use the wordpress plugin for putting the digg button.

How to put digg button in wordpress without plugin
How to put digg button in wordpress without plugin

You can use the following code in your wordpress theme for putting the digg button.

In loop you can use the following code.For Index.php file or archive.php or category.php you can use following code.


digg_url = '<?php the_permalink() ?>';
digg_title = '<?php the_title() ?>';
</script>

<span><span><span>
<span>0</span><a>digg</a></span></span></span>

In single page and pages or without loop you can use following code in single.php and page.php file. Use the following code.


<script type="text/javascript">// <![CDATA[
(function() { var s = document.createElement('SCRIPT'), <span class="hiddenSpellError" pre="" data-mce-bogus="1">s1</span> = document.getElementsByTagName('SCRIPT')[0]; s.type = 'text/javascript'; s.async = true; s.src = 'http://widgets.digg.com/buttons.js'; s1.parentNode.insertBefore(s, s1); })();
// ]]></script>

You can use various size of digg button in your wordpress site.

For above buttons you need to specify the button size in anchor class. as like following.

<script type="text/javascript">
(function() {
var s = document.createElement('SCRIPT'), s1 = document.getElementsByTagName('SCRIPT')[0];
s.type = 'text/javascript';
s.async = true;
s.src = 'http://widgets.digg.com/buttons.js';
s1.parentNode.insertBefore(s, s1);
})();
</script>
<!-- Medium Button -->
<a class="DiggThisButton DiggMedium"></a>
<!-- Large Button -->
<a class="DiggThisButton DiggLarge"></a>
<!-- Compact Button -->
<a class="DiggThisButton DiggCompact"></a>
<!-- Icon Button -->
<a class="DiggThisButton DiggIcon"></a>

how to show featured posts in wordpress homepage

For show featured posts in wordpress on home page. You can select article to show on home page. We have code snippet for show featured posts in wordpress. Showing featured post is good for seo also. Important and selected article you can show on home always. Featured post is great functionality introduced by wordpress.

show featured posts in wordpress

Some times we want to need to show featured posts in wordpress blogs on home page. You can select most popular or nice articles to show on home page. In this tutorial I will will show how you can show the featured wordpress posts on home page.

There is very simple way to show featured post on home page. First you need to create featured wordpress category and whatever post you want to show as featured post that posts select under featured post.

Then use following code:

<?php
  query_posts('category_name=featured&posts_per_page=5');
  if (have_posts()) : while (have_posts()) : the_post();
?>
<?php the_title(); ?>
<?php the_excerpt(); ?>
<?php endwhile; endif; ?>

Above code you need use in index.php and single.php file. Or you can following code for showing featured wordpress post.

 <?php while ( have_posts() ) : the_post() ?>

      <?php  if(get_post_meta($post->ID, 'type', true) == "featured") {; ?>
  <h2 class="entry-title"><a href="<?php the_permalink(); ?>" title="<?php printf( __('Permalink to %s', 'your-theme'), the_title_attribute('echo=0') ); ?>" rel="bookmark">
<img src="<?php echo get_post_meta($post->ID, 'intro_thump', true); ?>" alt="Icon for Post #<?php the_ID(); ?>" />
</a></h2>
<?php  }; ?>
<div class="entry-content">

     </div><!– .entry-content –>
<?php endwhile; ?>
show featured posts in wordpress
show featured posts in wordpress

Add google maps in wordpress post

You can add the google maps in wordpress post or pages very easily. You need to just use following code in your functions.php file. Open your functions.php file from your wordpress theme folder and copy paste the following code in that file.

Add google maps in wordpress post

You can Add google maps in wordpress post or pages very easily. Open your functions.php file from your wordpress theme folder and copy our code in file. If you don’t have functions.php file in your wordpress theme folder then create functions.php file and put following code in that file.


//Google Maps adding through Shortcode
function add_googlemap_in_wordpresss_in_wordpress($atts, $content = null) {
 extract(shortcode_atts(array(
 "width" => '620',
 "height" => '430',
 "src" => ''
 ), $atts));
 return '<iframe width="'.$width.'" height="'.$height.'" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="'.$src.'&output=embed" >';
}
add_shortcode("googlemap_in_wordpress", "add_googlemap_in_wordpresss_in_wordpress");

How to use google maps in your wordpress posts and pages.

use the following code in your posts or pages.

[googlemap_in_wordpress width="280" height="280" src="[you_url]"]
Add google maps in wordpress post
Add google maps in wordpress post

You can change the height and width as per your requirement and for url you need to use following url
http://maps.google.com/
go to above url and choose your location and right side top you will find the link option. click on that link url and you will get the link of your location. Just copy paste that url. example as follows

[googlemap_in_wordpress width="280" height="280" src="[http://maps.google.com/maps?f=q&source=s_q&hl=en&geocode=&q=New+York,+NY,+United+States&sll=37.0625,-95.677068&sspn=47.215051,79.013672&ie=UTF8&hq=&hnear=New+York&ll=40.555548,-73.730621&spn=0.356317,0.617294&z=11&iwloc=A]"]

Above code put in your post or page. you can see the google maps in your page.

Here is list of some wordpress plugins which will help you to integrate the google map in wordpress.

how to display or embed the google map in wordpress

wordpress plugin create table on activation

WordPress plugin tutorial, wordpress plugin create table on activation, If you are making plugin and in plugin many times we need to create new tables. In this article I will show you how easily we can create the wordpress plugin.

wordpress plugin create table on activation

wordpress plugin create table on activation
wordpress plugin create table on activation

Using following code you can create the table in wordpress database.

global $jal_db_version;
$jal_db_version = "1.0";

function jal_install () {
   global $wpdb;
   global $jal_db_version;

   $table_name = $wpdb->prefix . "liveshoutbox";
   if($wpdb->get_var("show tables like '$table_name'") != $table_name) {

      $sql = "CREATE TABLE " . $table_name . " (
	  id mediumint(9) NOT NULL AUTO_INCREMENT,
	  time bigint(11) DEFAULT '0' NOT NULL,
	  name tinytext NOT NULL,
	  text text NOT NULL,
	  url VARCHAR(55) NOT NULL,
	  UNIQUE KEY id (id)
	);";

      require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
      dbDelta($sql);

      $rows_affected = $wpdb->insert( $table_name, array( 'time' => current_time('mysql'), 'name' => $welcome_name, 'text' => $welcome_text ) );

      add_option("jal_db_version", $jal_db_version);

   }
}

Now that we have the initialization function defined, we want to make sure that WordPress calls this function when the plugin is activated by a WordPress administrator. To do that, we will use the activate_ action hook. If your plugin file is wp-content/plugins/plugindir/pluginfile.php, you’ll add the following line to the main body of your plugin:

register_activation_hook(__FILE__,'jal_install');

how to modify autosave Interval in wordpress

When you start writing post in wordpress panel. WordPress has facility to autosave the post with in every one minute. modify autosave Interval in wordpress.

how to modify autosave Interval in wordpress

how to modify autosave Interval in wordpress
how to modify autosave Interval in wordpress

When editing a post, WordPress uses Ajax to auto-save revisions to the post as you edit. You may want to increase this setting for longer delays in between auto-saves, or decrease the setting to make sure you never lose changes. The default is 60 seconds.

This really good feature of wordpress but sometimes this became very painful to blogger because of revision posts and size to database. Due to post revision wordpress post table size increases and Due to that database became slower.

So I recommend to change the auto save time of your wordpress.You can change the ‘auto-save’ time of wordpress blogs by your own time limit. This task invloves changin the configuration of AUTOSAVE_INTERVAL constant and replacing the given time interval by your time.

Just follow my steps very carefully. Open the wp-config.php file which you can find in your wordpress root folder.

and find the following sentence.

define('AUTOSAVE_INTERVAL', 60 ); // seconds

and change that to following


define('AUTOSAVE_INTERVAL', 180 ); // seconds

After doing this change upload wp-config.php file to server again. After this change Auto save will start after 3 min instead of 1 minute.

How to use the_excerpt in WordPress

We all know what is excerpt. In wordpress using excerpt is good idea. WordPress provides the inbuild function called the_excerpt. Many people want to to show first few words on the theme front page. For that this function is very useful.

How to use the_excerpt in WordPress

How to use the_excerpt in WordPress
How to use the_excerpt in WordPress

If you do not provide an explicit excerpt to a post (in the post editor’s optional excerpt field), it will display an automatic excerpt which refers to the first 55 words of the post’s content. Also in the latter case, HTML tags and graphics are stripped from the excerpt’s content.

Important Note: the_excerpt function must be written in The Loop.
For using the excerpt tag you need to put following code in the loop.

<!--?<span class="hiddenSpellError" pre="" data-mce-bogus="1">php</span> the_excerpt(); ?-->

Some times you need to put excerpt tag conditionally. In archive or category and home page you want to show only the excerpt of post then you can use following code:

<!--?<span class="hiddenSpellError" pre="" data-mce-bogus="1">php</span> if ( is_category() || is_archive() || is_home() ) {-->
	the_excerpt();
} else {
	the_content();
} ?-->

If you want to Control Excerpt Length using Filters use following code. To change excerpt length using excerpt_length filter, add the following code to functions.php file in your theme:

function new_excerpt_length($length) {
return 20;
}
add_filter('excerpt_length', 'new_excerpt_length');

use the_excerpt in WordPress

Tip: You can Remove […] string using Filters.By default, excerpt more string at the end is set to ‘[…]’. To change excerpt more string using excerpt_more filter, add the following code to functions.php file in your theme:

function new_excerpt_more($more) {
	return '[.....]';
}
add_filter('excerpt_more', 'new_excerpt_more');

If you want to make read more link after excerpt then use following code:

function new_excerpt_more($more) {
       global $post;
	return '<a href="'. get_permalink($post->ID) . '">' . 'Read the Rest...' . '</a>';
}
add_filter('excerpt_more', 'new_excerpt_more');

how to add adsense to wordpress blog

Many people wants to put ads on their wordpress blog because you can earn money from it. In this post we are going to show you step by step that how to add adsense in your wordpress site which is very simple. In article we shown steps for, how to add adsense to wordpress blog which is simple. Without code change you add google adsense in wordpress blog or website.

You might useful our another article of how many google ads you can show on single webpage. Hope you’ll find useful.

how to add adsense to wordpress blog

Lets get started.

  • Step 1: Login to your administrative and click on the Appearance menu which is on left side. When you will click on Appearance it will show you dropdown list, in that list you have to click on Widgets menu.

: Appearance >> Widgets

how to add adsense to wordpress blog
how to add adsense to wordpress blog

 

  • Step 2: Now choose a ” Text ” Widget and simply drag it in your Sidebar.
how to add adsense to wordpress blog
how to add adsense to wordpress blog
  • Step 3: Now a new window of your Text Widget will open. According to us you should add Advertisement for title and put the actual code that you have obtained from google under the title. Finally click on Save button which is on bottom right of window.

 

how to add adsense to wordpress blog
how to add adsense to wordpress blog

 

Well done! You have added adsense code in your wordpress blog.

set post excerpt length to limited characters in wordpress

In wordpress 3.0 limiting the excerpt is very easy. the_excerpt function is very useful and helpful in wordpress. In wordpress limiting the excerpt is very easy. With our code you can set post excerpt length to limited characters in wordpress. the_excerpt function is very useful and helpful in wordpress.

set post excerpt length to limited characters in wordpress

set post excerpt length to limited characters in wordpress
set post excerpt length to limited characters in wordpress

In many wordpress theme we used the excerpt. Many times we need to control excerpt characters as per our wordpress theme requirement. You can easily change the excerpt length using wordpress hook.

You just need to open your functions.php file from your wordpress theme folder and put following code in that.

function change_excerpt_length($length) {
    return 100;
}
add_filter('excerpt_length', 'change_excerpt_length');

This filter is used by wp_trim_excerpt() function. By default the excerpt length is set to return 55 words.