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
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.
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');
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
You just need to add following code in your wordpress theme’s functions.php file.
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.
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
Displays information about your blog, mostly gathered from the information you supply in your User Profile and General Options from the WordPress Administration panel.
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';
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.
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
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.
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.
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.”]
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.
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.
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.
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.
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:
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.