how to remove blog or category word from wordpress URL

Many times wordpress developer got requirement to remove the blog or category word from wordpress url. Code for remove blog or category word from wordpress.

how to remove blog or category word from wordpress URL

Many people and wordpress developer want to remove the blog or category wordpress from URL. This is really good for seo also. Many times wordpress developer got requirement to remove the blog or category word from wordpress url.

how to remove blog or category word from wordpress URL
how to remove blog or category word from wordpress URL

In this tutorial I will let you know how can you easily achieve this requirement. There is two-way to achieve this requirement. You can use the .htaccess file for fulfill this requirement.

Note: Apache mod_rewrite rule is must enable to with your Apache web server.

Open your .htaccess file which is present in your root folder of web hosting server. If not then create this file put it.

You can use the permanent redirect rewrite apache rule to achieve this. open your .htaccess file put following lines in that file


RewriteEngine On
RewriteBase /

#This rewrite rule we added for removing the category wordpress from URL
RewriteRule ^category/(.+)$ http://www.purabtech.in/files/$1 [R=301,L]

#This rewrite rule we added for removing the blog word wordpress from URL

RewriteRule ^blog/(.+)$ http://www.purabtech.in/files/$1 [R=301,L]

You can achieve this by changing in the code also. Use the following code do this changes. Open your theme folder and functions.php file and put following code in that file.


function remove_blog_word($without_blog_word_permalink)
{

if(!preg_match("/^\/blog\//",$without_blog_word_permalink))
return $without_blog_word_permalink;

$new_permalink=preg_replace ("/^\/blog\//","/",$without_blog_word_permalink );
return $new_permalink;

}

function remove_category_word($without_category_word_permalink)
 {

 if(!preg_match("/^\/category\//",$without_category_word_permalink))
 return $without_blog_word_permalink;

 $new_permalink=preg_replace  ("/^\/category\//","/",$without_category_word_permalink );
 return $new_permalink;

 }

add_filter("pre_update_option_permalink_structure","remove_blog_word");

add_filter("pre_update_option_permalink_structure","remove_category_word");

Just put above lines in your functions.php file and that will solve your issue.

how to pagination single post wordpress theme

If you are creating the bigger post then I recommend to in post pagination. Post pagination is supported by wordpress itself. Many people does not know about this facility of wordpress.

how to paginate the single wordpress post
how to paginate the single wordpress post

When you are writing the wordpress post just put <!–nextpage–> tag in your post. So from there next paragraph content will be show on next page but post will be same.

What is in post pagination?

WordPress tag similar to the more tag, except it can be used any number of times in a post, and each insert will “break” and paginate the post at that location. Hyperlinks to the paginated sections of the post are then generated in combination with the wp_link_pages() or link_pages() template tag.

If you are using the <!–nextpage–> tag in bigger post then wordpress post loading will more faster to your users.

Here I am going to tell you about <!–more–> tag also.  This tag is also very nice and good for showing some starting content of post.

What is more tag?

WordPress tag that breaks a post into “teaser” and content sections. Type a few paragraphs, insert this tag, then compose the rest of your post. On your blog’s home page you’ll see only those first paragraphs with a hyperlink ((more...)), which when followed displays the rest of the post’s content.

How to Embed a YouTube Video in WordPress

If you want to add the youtube or google and any third-party video in wordpress. It is really easily achievable. How to Embed a YouTube Video in WordPress.

How to Embed a YouTube Video in WordPress

WordPress itself provides to upload and submit youtube video in wordpress post. Just open wordpress admin panel and click on Add new post button.

Select the From URL tab. Paste the YouTube video’s URL into the URL field. Then click the Insert into Post button.

You can change the height and width of video using following code

[ youtube=http://www.youtube.com/watch?v=H2Ncxw1xfck&w=320&h=240]

I suggest to use Viper’s Video Quicktags wordpress plugin. I really like this wordpress plugin for embedding the third party video in wordpress blog or post.

You can download this plugin from following URL:

http://wordpress.org/extend/plugins/vipers-video-quicktags/

This plugin give you really great control with video player and size of video player. After installing the plugin you will find the “video quicktag” option in setting tab. Screenshot as follows:

Open the add new post tab, you will find very cool options for adding the video in post.

You just need to add the video URL in the dialog box.

How to show recent posts without wordpress plugin

When we are work with wordpress theme. So many times we want to show recent posts without wordpress plugin in wordpress theme.  Many people suggest to use wordpress plugin for showing the recent post.

How to show recent posts without wordpress plugin

But I suggest not to use any wordpress plugin for showing the recent posts in wordpress theme.

In this tutorial I will tell very simple technique to show recent posts. Following code you can use in your sidebar.php or in footer.php or anywhere as per your theme requirement.

Just put following code in your theme file. You just need to change the showposts count as per choice.


<?php
 $recent_posts = new WP_Query('showposts=15');
 while ($my_query->have_posts()) : $my_query->the_post();$do_not_duplicate = $post->ID;
?>

Your recent post will look this. You just need to customize css as per your wordpress theme.

show recent posts without wordpress plugin
show recent posts without wordpress plugin

create 404 page in wordpress theme with classic design

Many wordpress theme developer when create new wordpress theme, they need to think about 404 page must. In this article I going to give you information about how to create 404 page in wordpress theme with classic design.

create 404 page in wordpress theme

What is 404 page?

The 404 or Not Found error message is an HTTP standard response code indicating that the client was able to communicate with the server but the server could not find what was requested. 404 errors should not be confused with “server not found” or similar errors, in which a connection to the destination server could not be made at all. Another similar error is “410: Gone”, which indicates that the requested resource has been intentionally removed and will not be available again. A 404 error indicates that the requested resource may be available in the future.

I recommend to wordpress theme developer create customize 404 page in wordpress theme. Go to google custom search engine page and get google search engine code for your website from following URL:

http://www.google.com/cse/

Use following code creating the 404 page in wordpress theme.


<?php get_header(); ?>

<?php get_sidebar(); ?>

<div class="text" style="padding:50px 0 0 150px; ">

<img src="<?php bloginfo('template_url'); ?>/images/octocat_happy.gif">
<h1 class="title">Page Not Found</h1>
<p>We are sorry about!</p>
<p>Please try search again from here:</p><br>

<form action="http://images.purabtech.in/search-result/" id="cse-search-box">
<div>
<input type="hidden" name="cx" value="partner-pub-4949877136251097:p4u7h8-3y7v" />
<input type="hidden" name="cof" value="FORID:10" />
<input type="hidden" name="ie" value="ISO-8859-1" />
<input type="text" name="q" size="25" />
<input type="submit" name="sa" value="Search" />
</div>
</form>
<script type="text/javascript" src="http://www.google.com/cse/brand?form=cse-search-box&amp;lang=en"></script>

</div>

<?php get_footer(); ?>

I used here my websites search engine code. Dont forget to change the google search engine code as your web site.

404-error-pages-for-your-website-7 create 404 page in wordpress theme
create 404 page in wordpress theme
The 404 or Not Found error message is an HTTP standard response code indicating that the client was able to communicate with the server but the server could not find what was requested. 404 errors should not be confused with “server not found” or similar errors, in which a connection to the destination server could not be made at all. Another similar error is “410: Gone”, which indicates that the requested resource has been intentionally removed and will not be available again. A 404 error indicates that the requested resource may be available in the future.

How to create user registration in wordpress

People want to use wordpress for simple website registration module and user management module. We have solution to create user registration in wordpress. There is User and registration module present in wordpress but only through wordpress admin panel.

create user registration in wordpress

But Client dont want to show the worpress admin module to normal user. They want to create user profile page which is matching with there wordpress theme or website.

In this article I will give the tip about how to create user and registration module in wordpress.

First download Theme my profile wordpress plugin from following URL:

Theme My Profile

create user registration in wordpress
create user registration in wordpress

This plugin allows you to theme a user’s profile based upon their role. It even includes custom roles if you have any.

Install this plugin to your wordpress and use only subscriber for using the theme profile. This plugin will create the user profile page page to your wordpress website.

Next step is download Theme my login wordpress plugin from following URL:

This plugin themes the WordPress login, registration and forgot password pages according to your current theme. It replaces the wp-login.php file by using a page template from your theme. Also includes a widget for sidebar login.

Activate this plugin and choose options as per your choice. Above plugins are very easy to use and you can customize plugins as per your choice also.

Next step is download Profile pic wordpress plugin from following URL:

  1. Profile Pic
create user registration in wordpress
create user registration in wordpress

This plugin allows authors to add a picture to their profile and helps automate the process of displaying author profiles

Using both plugin you can easily achieve the User and Registration, login, forgot password, profile edit, user photo upload etc… functionality.

get recent comments without wordpress plugin

Showing the most recent comments is great for SEO purpose. Our code snippet will able to get recent comments without wordpress plugin in your wordpress site.

get recent comments without wordpress plugin

You can display the most recent comments of your entire blog without any wordpress plugin. Showing the most recent comments is great for SEO purpose. Your site will increase the visibility and people interaction. Socially you and your blog will became more famous. Using following code snippet you will be able to add the recent comments in your wordpress site.

I want to display the comments in footer area. I created following code. You can copy paste the code in your sidebar.php or footer.php file.

Using following code you are able to display recent comments with author’s gr-avatar also.


<?php
$total_comments = $wpdb->get_results("SELECT comment_date_gmt, comment_author, comment_ID, comment_post_ID, comment_author_email FROM $wpdb->comments WHERE comment_approved = '1' and comment_type != 'trackback' ORDER BY comment_date_gmt DESC LIMIT 10");
$comment_total = count($total_comments);
echo '<ul>';
for ($comments = 0; $comments < $comment_total; $comments++) {
echo "<div style='clear:both;width:355px;padding-top:3px;'><div style='float:left;width:35px;'>";
echo get_avatar($total_comments[$comments]->comment_author_email,$size='32',$default='<path_to_url>' );
echo "</div> <div style='width:320px;'>";
echo '<li>';
echo $total_comments[$comments]->comment_author . ' says ';
echo '<a href="'. get_permalink($total_comments[$comments]->comment_post_ID) . '#comment-' . $total_comments[$comments]->comment_ID . '">';
echo get_the_title($total_comments[$comments]->comment_post_ID);
echo '</a></li></div></div>';
}
echo '</ul>'
?>

My footer is looking like as follows:

get recent comments without wordpress plugin
get recent comments without wordpress plugin

how to create wordpress pages by script

For plugin or custom wordpress theme we need create wordpress pages by script. In this article we given code to how to create wordpress pages by script.

how to create wordpress pages by script

You can create the pages by using script. You can execute any script using the “$wpdb->insert” or

“$wpdb->query”.

For creating wordpress post or page you can use the wp_insert_post function. Before calling wp_insert_post() it is necessary to create an object (typically an array) to pass the necessary elements that make up a post. The wp_insert_post() will fill out a default list of these but the user is required to provide the title and content otherwise the database write will fail.

You can use following code for creating the page.  This code will execute when only you are logged in to wordpress.

// Create post object
  $my_post = array();
  $my_post['post_title'] = 'My post';
  $my_post['post_content'] = 'This is my post.';
  $my_post['post_status'] = 'publish';
  $my_post['post_author'] = 1;
  $my_post['post_type'] = 'page',
  $my_post['post_category'] = array(8,39);

// Insert the post into the database
  wp_insert_post( $my_post );

You can create wordpress plugin and use this code. Use following code for wordpress plugin. Copy the code and create the create_wordpress_pages.php file and put in plugin folder.

/*
Plugin Name: Create WordPress Pages
Plugin URI: http://images.purabtech.in/
Description: Create wordpress pages by script
Version: 1.0
Author: wordpressapi
Author URI: http://images.purabtech.in/
*/
function create_wordpress_pages(){
// Create post object
  $my_post = array();
  $my_post['post_title'] = 'My post';
  $my_post['post_content'] = 'This is my post.';
  $my_post['post_status'] = 'publish';
  $my_post['post_author'] = 1;
  $my_post['post_type'] = 'page',
  $my_post['post_category'] = array(8,39);

// Insert the post into the database
  wp_insert_post( $my_post );
}
register_activation_hook(__FILE__, 'create_wordpress_pages');
how to create wordpress pages by script
how to create wordpress pages by script

How to use pagination in wordpress post without plugin

There is difference between post pagination and in post pagination.If you want to keep pagination in wordpress post without plugin, Than use our code

When we are developing the new wordpress theme then we need to always need to think about post pagination and in post pagination. Yes, there is difference between post pagination and in post pagination.

How to use pagination in wordpress post without plugin

How to use pagination in wordpress post without plugin
How to use pagination in wordpress post without plugin

If you want to keep single post and pagination between in single post that is also possible through wordpress api. In this article I will show you hwo to use the in page or post pagination.

Open your single.php file from wordpress theme folder and put following code in that.

<?php wp_link_pages( ); ?>

We can pass the following parameter the this function.

<?php $args = array(
    'before'           => '<p>' . __('Pages:'),
    'after'            => '</p>',
    'link_before'      => ,
    'link_after'       => ,
    'next_or_number'   => 'number',
    'nextpagelink'     => __('Next page'),
    'previouspagelink' => __('Previous page'),
    'pagelink'         => '%',
    'more_file'        => ,
    'echo'             => 1 ); ?>
<?php wp_link_pages( $args ); ?>

This is the one of the sample code.

<?php wp_link_pages('before=</pre>
&after=
<pre>&next_or_number=number&pagelink=page %'); ?>

Now I will explain What wordpress doing for using this function. WordPress is using simple explode php function for using the next page tag. Like following way.

$content = get_the_content();
$pages = explode('<!--<span class="hiddenSpellError" pre="" data-mce-bogus="1">nextpage</span>-->', $content);

you can also use the above code in your loop.

how to display all months wordpress posts on homepage

In this article, we will show you how to retrieve wordpress posts within specific time frame and display all months wordpress post. code snippet with detail.

how to display all months wordpress posts on homepage

how to display all months wordpress posts on homepage
how to display all months wordpress posts on homepage

WordPress is providing as full proof wordpress api so we can achieve the this using wordpress api only.

You can use the query_posts() function for fetching the wordpress posts. Open your index.php from your wordpress template folder. Before loop just use the following code for in index.php file.


$current_date = getdate();
query_posts(monthnum=' .$current_date["mon"] );

You can pass the multiple parameters to query_posts function as per your requirement.

  • hour= – hour (from 0 to 23)
  • minute= – minute (from 0 to 60)
  • second= – second (0 to 60)
  • day= – day of the month (from 1 to 31)
  • monthnum= – month number (from 1 to 12)
  • year= – 4 digit year (e.g. 2009)
  • w= – week of the year (from 0 to 53)

Now I will show the another example. which will show only current date post on home page.


$current_date = getdate();
query_posts('year=' .$current_date["year"] .'&monthnum=' .$current_date["mon"] .'&day=' .$current_date["mday"] );

Another good example for fetching the 30 days latest post from wordpress

<!--?php
//based on Austin Matzko's code from wp-hackers email list
  function filter_where($where = '') {
    //posts in the last 30 days
    $where .= " AND post_date --> '" . date('Y-m-d', strtotime('-30 days')) . "'";
    return $where;
  }
add_filter('posts_where', 'filter_where');
query_posts($query_string);
?>

Using above code you can display all months wordpress posts.