disable image upload for wordpress users

wordpress tutorial, disable image upload for wordpress users. If you want to restrict the normal author to upload media file your wordpress blog.  So you can use the following code in your functions.php file.

disable image upload for wordpress users

disable image upload for wordpress users
disable image upload for wordpress users

Following function will remove the upload media button from wordpress dashboard.


//remove the upload buttons for auther and other wordpress user
function removemediabuttons()
{
if($user->wp_user_level >= 1) {
remove_action( 'media_buttons', 'media_buttons' );
}

}
add_action('admin_head','removemediabuttons');

Following code will remove the media library tab from the Add new post section for all the users.
Restricts media library access (subscriber) under the “add new post”

function remove_medialibrary_tab($tabs) {
unset($tabs['library']);
return $tabs;
}
add_filter('media_upload_tabs','remove_medialibrary_tab');

This hack is very important for wordpress developers. when you are developing the multiuser wordpress site.

timthumb php script for image resizing with wordpress

wordpress tutorial, timthumb php script for image resizing with wordpress. We all know what is the tumthumb script. mainly the worpdress theme developers used the tumthumb php script for resizing the images.

timthumb php script for image resizing with wordpress

But now we dont need to use the tumthumb script in wordpress theme because wordpress api is supporting the similier functionality in wordpress.

Using the wordpress hook we can specify the thumbnail size.

You can set the post image thumbnail size using wordpress hook.

Just copy paste the following code in to your functions.php file


function custom_thumbnail_size() {
return 128; // or whatever you want
}
add_filter('wp_thumbnail_max_side_length','custom_thumbnail_size');

timthumb php script for image resizing with wordpress
timthumb php script for image resizing with wordpress

how to make an email address clickable in wordpress

wordpress tutorial, how to make an email address linkable in wordpress. Here we given very simple and short code which you can add in theme.

When ever we insert the URL , email  in post we need to put the link manually. WordPress provided the way to automatically make the URL and Email clickable in wordpress post.

how to make an email address clickable in wordpress

how to make an email address clickable in wordpress

You just need to add following code in your wordpress theme’s functions.php file.

add_filter('the_content', 'make_clickable');

For more help you can check following URL:
http://codex.wordpress.org/Function_Reference/make_clickable

How to set post first image as featured image automatically

So using or choosing the image as featured image for post is another manual work we need to do. Info about. how to set post first image as featured image. We have SQL query for this.

From wordpress 3.0 version wordpress launched the feature called featured image. Many new wordpress themes are compatible with new wordpress version. So using or choosing the image as featured image for post is another manual work we need to do.

Many old wordpress website holder or blogger is having issue with this functionality. What they want is when they create the post they haven’t set the featured image, but they would like the featured image to default to the image that has been included in the post.

Some wordpress always use the first image as featured image but old post was not updated with featured image. They need to do manual work to set the featured image. I also faced same issue.

After doing some R&D I found the solution. If you want to set the your posts first image as featured image then use my following code.

For using the code you need to open your mysql database command prompt or phpmysqladmin program and select your wordpress database and execute the following query in that.

insert into wp_postmeta (meta_value, meta_key, post_id) select DISTINCT(ID), post_type , post_parent from wp_psts where post_type= 'attachment' and post_parent !=0 and post_status='inherit';<br /><br />update wp_postmeta set meta_key = '_thumbnail_id' where meta_key='attachment'

Using above sql query you will be able to set the featured image to your old and new post from post content. If you are having any issues with using this sql then write to me.

How to set post first image as featured image automatically
How to set post first image as featured image automatically

How to use bloginfo in wordpress theme

For each wordpress theme developer the bloginfo() function is very useful. If you are not used the bloginfo function then use the bloginfo function. There is great help is provided wordpress api. In every wordpress theme we need to use the bloginfo method. bloginfo() function is useful. If you not used bloginfo function than use bloginfo function. Every theme we need to use bloginfo in wordpress theme.

How to use bloginfo in wordpress theme

How to use bloginfo in wordpress theme
How to use bloginfo in wordpress theme

Displays information about your blog, mostly gathered from the information you supply in your User Profile and General Options from the WordPress Administration panel.

Following parameter is passed in this method.


name = TestWpapi
description = Just another WordPress blog
admin_email = admin@example

url = http://example/home
wpurl = http://example/home/wp

stylesheet_directory = http://example/home/wp/wp-content/themes/child-theme
stylesheet_url = http://example/home/wp/wp-content/themes/child-theme/style.css
template_directory = http://example/home/wp/wp-content/themes/parent-theme
template_url = http://example/home/wp/wp-content/themes/parent-theme

atom_url = http://example/home/feed/atom
rss2_url = http://example/home/feed
rss_url = http://example/home/feed/rss
pingback_url = http://example/home/wp/xmlrpc.php
rdf_url = http://example/home/feed/rdf

comments_atom_url = http://example/home/comments/feed/atom
comments_rss2_url = http://example/home/comments/feed

charset = UTF-8
html_type = text/html
language = en-US
text_direction = ltr
version = 2.9.2

following is examples for using the bloginfo() method.

//Show Blog Description

//Show Blog Title

//ading the style.css
//ping back url
//for content type

How to use the bloginfo() function in wordpress theme
How to use the bloginfo() function in wordpress theme

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

Media Library not displaying images after importing posts

Earlier I have blog in wordpressmu  then after wordpress 3.0 version I decided to migrate to new version. I exported my all posts by using the wordpress  export tool. Then I imported data into new wordpress installation. I got all my posts and category and all the data. Then I checked all my attachments.

Then I saw my media library I saw all the images listing are there but images are not showing in media library. Media Library not displaying images after importing posts. I personally faced issue and got frustrated. then I solved issue myself using mysql query trick.

Media Library not displaying images after importing posts

Media Library not displaying images after importing posts
Media Library not displaying images after importing posts

When I checked my database I saw the all the my attachments are listed in post table but images are not displaying. All the places I only saw the wp-includes/images/crystal/default.png image.

I did spend one hour googled for solving the issue but I did not find any solution for this. Than again I checked my Folder permissions and images files but I found all things are perfect.
Then I checked my database and I found the issue. in wp_posts table ->post_mime_type column one entry was missing. After seeing that issue I fixed the issue.

I used the following mysql quires using myphpadmin tool.

[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.”]

Update wp_posts set post_mime_type='image/jpg' WHERE guid like '%jpg%'
Update wp_posts set post_mime_type='image/jepg' WHERE guid like '%jepg%'
Update wp_posts set post_mime_type='image/png' WHERE guid like '%png%'
Update wp_posts set post_mime_type='image/gif' WHERE guid like '%gif%'

[/viral-lock]

After using above query I checked the my media library. I am able to see my all images in media library.

My advise to you is first take backup of your database and then use above mysql quires. Then use the above queries.

If you are imported post from other website then use following commands also.


UPDATE wp_posts SET post_content = REPLACE(post_content, 'NEW-DOMAIN-NAME', 'files/');

UPDATE wp_posts SET post_excerpt = REPLACE(post_excerpt, 'NEW-DOMAIN-NAME', 'OLD-DOMAIN-NAME');

UPDATE wp_posts SET guid = REPLACE(guid, 'NEW-DOMAIN-NAME', 'OLD-DOMAIN-NAME');

Above quires will change the domain location of file.

most popular posts wordpress without plugin

Many times you want to show the popular posts in your wordpress theme and you use popular post wordpress plugin or widget for showing the popular posts in your wordpress theme. As much possible you need to avoid the wordpress plugins for minimal code.

most popular posts wordpress without plugin

With very easy steps you can fetch the most popular posts from your wordpress. Most common trick or technique is on comments base you can fetch the popular posts.

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


// Get Most Popular Posts in theme
function popular_posts_by_comments( $posts = 5) {
 $popular = new WP_Query('orderby=comment_count&posts_per_page='.$posts);
 while ($popular->have_posts()) : $popular->the_post();
?>
<li>
<div>
 <a title="<?php the_title(); ?>" href="<?php the_permalink() ?>"><?php the_title(); ?></a>
 <span><?php comments_popup_link('0 Comment', '1 Comment', '% Comments', 'comments-link', ''); ?></span>
 </div> <!--end .info-->
 <div></div>
</li>
<?php endwhile;
}

This is very easy code to fetch you wordpress popular posts. Here I am fetching only 5 popular posts from wordpress. You can fetch the multiple popular posts by changing the $post variable value.

In wordpress theme sidebar or footer section if you want to show the popular post then just use following code.

popular_posts_by_comments();

most popular posts wordpress without plugin
most popular posts wordpress without plugin

where you want to show the popular posts.

show popular posts without wordpress plugin in theme
show popular posts without wordpress plugin in theme

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.