Import wordpress attachment without download images

Everybody knows how to use the wordpress import and export functionality. When you don’t want to download the wordpress post attachment (images, files) then you should follow my steps. Using following steps you are able to import all the attachment data without downloading the images.

Import wordpress attachment without download images

First Open your old wordpress installation and then go to wordpress panel. Then open your phpmyadmin of old wordpress installation and run following query.

update `wp_posts` set `post_type`='image' where `post_type`='attachment';
Import wordpress attachment without download images
Import wordpress attachment without download images

This query will create the image post type and attachments will become like post type. Then use the wordpress export and download exported xml.

 

Then open your new wordpress admin and click on import button and import the whole xml file.

You will see the you selected the download and import file attachments option but files are not downloaded.

Then through ftp client transfer all your image and files to new installation. Then open phpmyadmin of new wordpress panel and use following command.


update `wp_posts` set `post_type`='attachment' where `post_type`=image';

Now you are able to see the images in new wordpress panel and website.

Import wordpress attachment without download images
Import wordpress attachment without download images

convert plain text URI to HTML links in wordpress themes

When you put some URL and email address you need to manually add the link URL to that text. This action always takes the some time of wordpress blogger. WordPress has facility to add the links to your URL and email address automatically.

 

convert plain text URI to HTML links in wordpress

This facility is available in wordpress since wordpress 2.7 version but many wordpress theme and plugin developers never used this functionality.

WordPress provides the make_clickable() function for convert plain text URI to HTML links. This function able to convert URI, www, ftp, and email addresses. Finishes by fixing links within links. You just need to pass the string parameter to this method.

More detail information you can find in following file.
wp-includes/formatting.php.

You can use this method in your functions.php file also. Use the following code.

add_filter('the_content', 'make_clickable');

By using this code you are able to covert the URI, www, ftp, and email addresses in to link.

If you are having any issues or question about make_clickable method then please write to me.

optimize wordpress database using phpmyadmin

Sometimes our wordpress tables became so big and we need to worry about wordpress database and table size. Big table always take extra time to execute the query. For this issue we need to keep our wordpress tables clean and do optimization time to time.

optimize wordpress database using phpmyadmin

Optimize wordpress database using phpmyadmin. For optimization, We used 2 tools which are reliable. We used wp-optimize wordpress plugin and PhpMyAdmin tool.

WP-Optimize is a wordpress database cleanup and optimization tool. It doesn’t require PhpMyAdmin to optimize your database tables. It allows you to remove post revisions, comments in the spam queue, un-approved comments within few clicks.

optimize wordpress database using phpmyadmin
optimize wordpress database using phpmyadmin

Second tool I used which is PhpMyAdmin. Using know which tables are over flowing and over size. In wp-optimize panel you will which tables are needed the optimization. Just open your phpmyadmin and select your wordpress database. Click on”Check tables having overhead” link, that will select the overhead tables from your wordpress database. Than just select the Optimize table option.

optimize wordpress database using phpmyadmin
optimize wordpress database using phpmyadmin

This action will just execute the following query.


optimize  table wp_posts, wp_comments;

if you want to optimize another tables then just use the above query. OPTIMIZE TABLE should be used if you have deleted a large part of a table or if you have made many changes to a table with variable-length rows (tables that have VARCHAR, VARBINARY, BLOB, or TEXT columns). Deleted rows are maintained in a linked list and subsequent INSERT operations reuse old row positions. You can use OPTIMIZE TABLE to reclaim the unused space and to defragment the data file.

For MyISAM tables, OPTIMIZE TABLE works as follows:

  1. If the table has deleted or split rows, repair the table.
  2. If the index pages are not sorted, sort them.
  3. If the table’s statistics are not up to date (and the repair could not be accomplished by sorting the index), update them.

If you having any issues or question about optimizing table then please do write to me.

how to create contact us page without plugin

Every wordpress site is need to contact us page for there website or blog. All the people use the wordpress plugin for creating the contact us page. When you install the wordpress plugin that will install some extra code to your wordpress site. After using wordpress plugin you need some customization in that plugin due to UI. You need R&D time and development time. Code for contact us page without plugin.

contact us page without plugin

In this article I will show how you can create the contact us page with out any wordpress plugin. Using following code you can create the contact us form very easily.

First create contact-us.php page in your wordpress theme folder and put following code in that file.

[viral-lock message=”Solution code is Hidden! It’s Visible for Users who Liked/Shared This article on Facebook or Twitter or Google+. Like or Tweet this article to reveal the content.”]


<?php
/*
Template Name: Contact Us
*/
if($_POST[sent]){
 $error = "";
 if(!trim($_POST[your_name])){
 $error .= "<p>Please enter your name</p>";
 }
 if(!filter_var(trim($_POST[your_email]),FILTER_VALIDATE_EMAIL)){
 $error .= "<p>Please enter a valid email address</p>";
 }
 if(!trim($_POST[your_message])){
 $error .= "<p>Please enter a message</p>";
 }
 if(!trim($_POST[your_subject])){
 $error .= "<p>Please enter a message</p>";
 }
 if(!$error){
 $email = wp_mail(get_option("admin_email"),trim($_POST[your_name])." sent you a message from ".get_option("blogname"),stripslashes(trim($_POST[your_message])),"From: ".trim($_POST[your_name])." <".trim($_POST[your_email]).">\r\nReply-To:".trim($_POST[your_email]));
 }
}
?>
<?php get_header(); ?>
<div id="container">
 <div id="content" role="main">
 <?php if ( have_posts() ) while ( have_posts() ) : the_post(); ?>
 <div id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
 <h1><?php the_title(); ?></h1>
 <div>
 <?php if($email){ ?>
 <p><strong>Message succesfully sent. I'll reply as soon as I can</strong></p>
 <?php } else { if($error) { ?>
 <p><strong>Your messange hasn't been sent</strong><p>
 <?php echo $error; ?>
 <?php } else { the_content(); } ?>
 <form action="<?php the_permalink(); ?>" id="contact_me" method="post">
 <input type="hidden" name="sent" id="sent" value="1" />
 <div id="form">
 <div id="lebel">Your Name (required)</div>
 <div id="input-field"><input type="text" name="your_name" id="your_name" value="<?php echo $_POST[your_name];?>" /></div>
 <div id="lebel">Your Email (required)</div>
 <div id="input-field"><input type="text" name="your_email" id="your_email" value="<?php echo $_POST[your_email];?>" /></div>
 <div id="lebel">Subject</div>
 <div id="input-field"><input type="text" name="your_subject" id="your_subject" value="<?php echo $_POST[your_subject];?>" /></div>
 <div id="lebel">Your Message(required)</div>
 <div id="input-field"><textarea name="your_message" id="your_message"><?php echo stripslashes($_POST[your_message]); ?></textarea></div>
 <div id="lebel"> </div>
 <div id="input-field"><input type="submit" name = "send" value = "Send email" /></div>
 </div>

 </form>
 <?php } ?>
 </div><!-- .entry-content -->
 </div><!-- #post-## -->
 <?php endwhile; ?>
 </div><!-- #content -->
</div><!-- #container -->
<?php get_sidebar(); ?>
<?php get_footer(); ?>

[/viral-lock]

Then go to your wordpress admin panel. Create page called contact us. In Right side panel you will find the “page attribute” section. From template drop down choose the Contact Us option. and create the contact us page.

contact us page without plugin
contact us page without plugin

WordPress uses the wp_mail() function for sending the email. all wordpress plugin also use the wp_mail() function for sending the email.

If you are having issues with sending the email with this function then you should use the different SMTP mail server for sending mail.

For sending email through SMTP  in detail you should check the following article.

https://purabtech.in/send-smtp-email-wordpress-plugin/

With this code you can write your own CSS for styling the contact form as per your wordpress theme. If you are having any issues or question about this script then please write to me.

All wordpress websites has requirement to add the contact form in there website. We always searching for wordpress contact form code, wordpress simple contact form, wordpress contact form with captcha, wordpress default contact form, wordpress contact form without plugin, wordpress contact form not sending email, wordpress custom contact form, best wordpress contact form solution. We can easily add the contact form without using any wordpress plugin very easily. You can use the my code snippet in your wordpress theme and you will be able to add the wordpress contact form.

custom post type permalink not working wordpress

From WordPress 3.0 version we are able to use the custom_post_type. In installation time of theme or plugin new permalink structure will be created and you can easily able to use the custom post type permalink.

custom post type permalink not working wordpress
custom post type permalink not working wordpress

If your custom_post_type function is having some issues then wordpress permalink for your custom post type will not work. If your custom post type permalink is not working properly then normally you will get the 404 page and message saying page not found.
Your wordpress does not create the permalink structure aumatically so you need to recreate the Rewrite rules again with wordpress.

If you not added following code in you custom_post_type function then please add the following code:

'rewrite' => array(
 'slug' => 'issue',
 'with_front' => FALSE,
 ),

The right way to use rewrite rule in function is as follows;

register_post_type( 'movies',
 array( 'label' => __('Movies')
, 'public' => true,
'show_ui' => true ,
'rewrite' => array( 'slug' => 'movies', 'with_front' => false )
 ) );

If you are still facing issue and 404 page is coming then go the your wordpress panel -> setting- > permalink page and hit save changes button.
That will flushes the rewrite rules and build rewirte rules again in wordpress.

How to send smtp email through wordpress without plugin

Many people want to send smtp email through wordpress. WordPress uses the PHPmailer in there CMS. Using PHPmailer you can send the email using STMP service.

send smtp email through wordpress

But many wordpress developer dont know how to use the wordpress phpmailer functionality. Using PHPmailer you can send the email using STMP service.

send smtp email through wordpress
send smtp email through wordpress

send smtp email through wordpress, wordpress send email smtp

Many people use the wordpress plugins for sending the email. But I recommend not to use any wordpress plugin code for this. Because many of wordpress plugin code are not necessary and that will not useful for your wordpress application.

Here in this article I will show you how to sent email using wordpress with SMTP settings.

Use the following code for this:

[viral-lock message=”Source code is Hidden! It’s Visible for Users who Liked/Shared This article on Facebook or Twitter or Google+. Like or Tweet this article to reveal the content.”]


// SMTP email sent
require_once ABSPATH . WPINC . '/class-phpmailer.php';
require_once ABSPATH . WPINC . '/class-smtp.php';
$phpmailer = new PHPMailer();
$phpmailer->SMTPAuth = true;
$phpmailer->Username = 'Username';
$phpmailer->Password = 'password';

$phpmailer->IsSMTP(); // telling the class to use SMTP
$phpmailer->Host       = "hostname.com"; // SMTP server
$phpmailer->FromName   = $_POST[your_email];
$phpmailer->Subject    = $_POST[your_subject];
$phpmailer->Body       = $_POST[your_message];                      //HTML Body
$phpmailer->AltBody    = "To view the message, please use an HTML compatible email viewer!"; // optional, comment out and test
$phpmailer->WordWrap   = 50; // set word wrap
$phpmailer->MsgHTML($_POST[your_message]);
$phpmailer->AddAddress('support@purabtech.in/files/', 'Wordpress support');
//$phpmailer->AddAttachment("images/phpmailer.gif");             // attachment
if(!$phpmailer->Send()) {
 echo "Mailer Error: " . $phpmailer->ErrorInfo;
} else {
 echo "Message sent!";
}

[/viral-lock]

Use the above code for sending the email from wordpress. With godaddy hosting service above code is very useful for creating the contact us page.

Many wp developers asked me where to add the above code. So here is answer. You can create wordpress theme template page. Like contact us page and add the above code in that page according to your requirement.

Here are some useful links:

How to create contact us template page in wordpress

how to create contact us page without plugin

If you are having any issues or question about using the code then please write to me.

how to serve wordpress images from subdomain

creating sub domain for wordpress images is best way to increase your wordpress site speed. We given steps to, how to serve wordpress images from sub domain. Many shared hosting and wordpress bloggers and  websites are using the apache web server for hosting the wordpress sites. Apache Web server is having his own rules and behavior. By default when you open webpage of your website. That time you are making so many requests to apache web server with same domain name. That will create queue to apache web server with same domain name.

how to serve wordpress images from subdomain

For reducing the load time you should keep image file on different sub domain. Means though image subdomain you can send a parallel request to Apache web server. It will reduce the concurrent connections to web server. WordPress provides the functionality to set different domain or sub domain for images.

In this article I will show you how easily you can set the wordpress images from sub domain. First create subdomain through your control panel. Use following step for creating subdomain.

how to serve wordpress images from subdomain
how to serve wordpress images from subdomain

I recommend to create the images subdomain because images subdomain is good for SEO. Here I created the purabtech.in/files/ subdomain for my images. Then set your wordpress images path in document root setting. Normally your wordpress images are stored in wp-content/uploads directory. You can use following setting for setting the document root.

how to serve wordpress images from subdomain
how to serve wordpress images from subdomain

After creating subdomain for images and setting up the correct document root for images subdomain. Go to your wordpress admin panel. From right side panel you should go to settings -> Media panel. This page will look like as follows:

how to serve wordpress images from subdomain
how to serve wordpress images from subdomain

In “Full URL path to files” textbox put your image subdomain name and click on save changes button. Uncheck the organize my uploads into month- and year-based folder option because which is not good for SEO purpose.

After this your images will come from image subdomain but old uploaded image files will still come from older location and same domain. For changing the older images file location and domain information you should use the following steps.

Go to your Mysql databases and select the your wordpress database. You can use the phpmyadmin sql manager for this or you can use command prompt for this if you are having dedicated hosting server. If you taken shared hosting then I recommend to use PhpMyAdmin.

Use following two SQL query: (Note: You should use your images subdomain and your domain name in SQL query)


UPDATE wp_posts SET post_content = REPLACE(post_content,'http://images.purabtech.in/','http://images.purabtech.in/');

UPDATE wp_posts SET guid = REPLACE(guid,'http://images.purabtech.in/','http://images.purabtech.in/');

After this your old images files will point to images subdomain. If your images and wordpress website is old then google and other search engines already indexed your images. So We need to write the redirection rewrite rule for images in your .htaccess file. This file you will find in your Root directory of wordpress installation.

Use following line of code in your .htaccess file.


RewriteEngine On
RewriteBase /

RedirectMatch 301 ^/wp-content/uploads/(.*)$ http://images.purabtech.in/$1

Above all steps are important to change the wordpress images into images subdoamin. If you are having any issues or questions about this article. Then please write to me.

File upload with meta box in wordpress with custom post type

Code for File upload with meta box in wordpress using custom post type using meta boxes in wordpress. From wordpress 3.0 version wordpress introduced the custom_post_type function. Many people want to attach the file field with add_meta_box function. In this tutorial I will tell you how to upload file with custom meta box and post type. I tested above code with new wordpress versions 3.9. Still code is working fine.

Code for File upload with meta box in wordpress using custom post type using meta boxes in wordpress.

In this tutorial I will show you how to create the custom post type and add custom meta boxes to that post type and upload file with custom meta box.

After digging into wordpress files and functions I created following code. Just open your functions.php file and put following code in that file for creating custom post type.


<?php
 add_action('init', 'create_product');
 function create_product() {
 $product_args = array(
 'label' => __('Product'),
 'singular_label' => __('Product'),
 'public' => true,
 'show_ui' => true,
 'capability_type' => 'post',
 'hierarchical' => false,
 'rewrite' => true,
 'supports' => array('title', 'editor', 'thumbnail')
 );
 register_post_type('product',$product_args);
 }
?>

For uploading the file through custom meta box use the following code. Following code will add the file field to custom meta box and you are able to upload file or image to wordpress and upload file attachment to you custom post. Following code is very helpful to many wordpress theme and plugin developer. If you are having any issues or trouble using code then get back to me.

File upload with add_meta_box or custom_post_type in wordpress File upload with meta box in wordpress
File upload with add_meta_box or custom_post_type in wordpress File upload with meta box in wordpress

<?php

 add_action("admin_init", "add_product");
 add_action('save_post', 'update_purchase_url');
 function add_product(){
 add_meta_box("product_details", "product Options", "product_options", "product", "normal", "low");
 }
 function product_options(){
 global $post;
 $custom = get_post_custom($post->ID);
 $purchase_url = $custom["purchase_url"][0];
 $product_price = $custom["product_price"][0];
 $product_image = $custom["product_image"][0];
 $video_code = $custom["video_code"][0];

?>
 <div id="product-options">
 <label>Purchase URL:</label>php echo $purchase_url; ?>" />

 <label>Product Price:</label>php echo $product_price; ?>" />

 <label>Product Image:</label>php echo $product_image; ?>" />
 <img src="<?php echo $product_image; ?>">

 </div><!--end product-options-->
<?php
 }
 function update_purchase_url(){
 global $post;
 update_post_meta($post->ID, "purchase_url", $_POST["purchase_url"]);
 update_post_meta($post->ID, "product_price", $_POST["product_price"]);
 update_post_meta($post->ID, "product_image", $_POST["product_image"]);

 if(!empty($_FILES['product_image']['name'])){ //New upload
 require_once( ABSPATH . 'wp-admin/includes/file.php' );
 $override['action'] = 'editpost';

 $uploaded_file = wp_handle_upload($_FILES['product_image'], $override);

 $post_id = $post->ID;
 $attachment = array(
 'post_title' => $_FILES['product_image']['name'],
 'post_content' => '',
 'post_type' => 'attachment',
 'post_parent' => $post_id,
 'post_mime_type' => $_FILES['product_image']['type'],
 'guid' => $uploaded_file['url']
 );
 // Save the data
 $id = wp_insert_attachment( $attachment,$_FILES['product_image'][ 'file' ], $post_id );
 wp_update_attachment_metadata( $id, wp_generate_attachment_metadata( $id, $_FILES['product_image']['file'] ) );

update_post_meta($post->ID, "product_image", $uploaded_file['url']);
 }
 }
?>

For Uploading the file your post form need to add the enctype=”multipart/form-data” type to your form. Just use the following code in your functions.php file.

[viral-lock message=”Solution code is Hidden! It’s Visible for Users who Liked/Shared This article on Facebook or Twitter or Google+. Like or Tweet this article to reveal the content.”]


<?php
function fileupload_metabox_header(){
?>
<script type="text/javascript">
 jQuery(document).ready(function(){
 jQuery('form#post').attr('enctype','multipart/form-data');
 jQuery('form#post').attr('encoding','multipart/form-data');
 });
</script>
<?php }
add_action('admin_head', 'fileupload_metabox_header');

?>

[/viral-lock]

For checking all information in edit or preview section use following code.


<?php

add_action("manage_posts_custom_column",  "product_custom_columns");
add_filter("manage_edit-product_columns", "product_edit_columns");

function product_edit_columns($columns){
 $columns = array(
 "cb" => "<input type=\"checkbox\" />",
 "title" => "Product Title",
 "purchase_url" => "Purchase URL",
 "product_price" => "Product Price",
 "product_image" => "Product Image",
 );
 return $columns;
}
function product_custom_columns($column){
 global $post;
 switch ($column) {
 case "purchase_url":
 $custom = get_post_custom();
 echo $custom["purchase_url"][0];
 break;
 case "product_price":
 $custom = get_post_custom();
 echo $custom["product_price"][0];
 break;
 case "product_image":
 $custom = get_post_custom();
 $img_url =$custom["product_image"][0];
 echo "<image src=".$img_url." height=100 width=100 />";
 break;
 }
}

?>

File upload with meta box in wordpress
File upload with meta box in wordpress

Above code is useful for any type of customization. If you are having any issue with using this code then please get back to me.

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 can user delete their own account from WordPress site

Creating, editing and deleting the user account is a very basic need of any CMS. We can easily allow user to register their account in wordpress sites. We shown in this article, How can user delete their own account from wordPress site. We can use many wordpress plugins and create User profile and manage their profile.

How can user delete their own account from WordPress site

How can user delete their own account from WordPress site
How can user delete their own account from WordPress site

But in wordpress deleting the User from wordpress site is not easy. Here in this article I will tell how can we easily delete the user account without administrator permission.

Using following wordpress plugin we can achieve this functionality.

User Self Delete

This plugin will allow your users to delete their own account without any need for interaction on the administrator’s behalf.

When a user wishes to delete their account, they are taken to a confirmation page where they must enter the word “yes” in order for the deletion to take place. Once they type “yes” and press the delete account button, they are redirected to the login page and they no longer exist as a user on your site.