Like Us Like Us Facebook Subscribe Subscribe us YouTube Whatsapp Share us Whatsapp Query Send your queries

How to add a field on the WordPress Users profile

How to add a field on the WordPress Users profile

If you want to add an extra field on WordPress User profile, then we can do it using plugins or adding some code in “functions.php” . In this tutorial I using the second method. Each and every WordPress theme has a file called functions.php , we have to just open this file and paste the code given below

Code given below will create some extra field like contact, gender


//extra fields
add_action( 'show_user_profile', 'my_show_extra_profile_fields' );
add_action( 'edit_user_profile', 'my_show_extra_profile_fields' );
function my_show_extra_profile_fields($user){
//$user_id=1;//sanitize_text_field($_GET['user_id']);
?> <h3>Contact No.</h3>
<table class="form-table">
<tr>
<th><label for="twitter">Contact</label></th>
<td>
<input type="text" name="contact" id="contact" value="<?php echo esc_attr( get_the_author_meta( 'contact', $user->ID ) ); ?>" class="regular-text" /><br />
<span class="description">Please enter your Contact No.</span>
</td>
</tr>
<tr>
<th><label for="twitter">Gender</label></th>
<td>
<select name="gender" id="gender" class="regular-text">
<option value="<?php echo esc_attr( get_the_author_meta( 'gender', $user->ID ) ); ?>"><?php echo esc_attr( get_the_author_meta( 'gender', $user->ID ) ); ?></option>
<option value="Male">Male</option>
<option value="Female">Female</option>
</select>
<span class="description">Please Select your Gender</span>
</td>
</tr>
</table>

<?php }

add_action( 'personal_options_update', 'my_save_extra_profile_fields' );
add_action( 'edit_user_profile_update', 'my_save_extra_profile_fields' );
function my_save_extra_profile_fields($user_id) {
if ( !current_user_can( 'edit_user', $user_id ) )
return false;
update_user_meta( $user_id, 'contact', $_POST['contact'] );
update_user_meta( $user_id, 'gender', $_POST['gender'] );
}

Screen shot for How to add a field on the WordPress Users profile

Now go to your profile page You will able to see contact and gender field.

Displaying Recent Post in WordPress with small thumbnails

Displaying Recent Post in WordPress with small thumbnails

In this post I am going to show you how to display recent post with small thumbnails, I have used this code in one of my client’s website in footer region. First thing is to add support to your theme For feature image.

WordPress custom theme Featured image support

First open your theme’s  function.php and paste code below :

add_theme_support( 'post-thumbnails' );
add_image_size( 'footer-thumb', 64, 64, false );

You can change 64,64 to your own suppose you want to show image with resolution 120*100 then use add_image_size( 'footer-thumb', 120, 100, false );

Now we are going to create a php code to display images .

<h2>Recent Post</h2>
<?php
$args = array( 'numberposts' => '4' );
$recent_posts = wp_get_recent_posts( $args );
foreach( $recent_posts as $recent ){
echo get_the_post_thumbnail($recent["ID"], 'footer-thumb');
echo '&nbsp;&nbsp;<a href="'.get_permalink($recent["ID"]). '" style="color:#ffffff">' .$recent["post_title"].'</a> ';
}
?>

Paste above this code area where you want to show recent post.

Solve WordPress FTP Error while Installing plugins on Linux

Solve WordPress FTP Error while Installing plugins on Linux

When we  develop Website using WordPress on Linux using Xampp or Lampp, while installing Plugins WordPress asks FTP details. This happens due to wordpress  folder’s user ownership  issue.

How to know user name,  create a php file user.php with code

<?php echo exec(‘whoami’); ?>

Run this file on localhost, if you use xampp outout will daemon and if you use lampp output will be www-data.

We will solve this problem using Command chown  to Change both the owner and group of folder in single command.

What is chown – To change owner, change the user and/or group ownership of each given File to a new Owner. Chown can also change the ownership of a file to match the user/group of an existing reference file.

Now open terminal or konsole run this command to change user and group of  wordpress folder.

sudo chown -R user:group  /path/to/directory

for xampp sudo chown -R daemon:daemon /opt/lampp/htdocs/wordpress folder name

Now you can install plugins, theme on just one click.

You can also watch my YouTube video Solve WordPress FTP Error while Installing plugins on Linux at https://youtu.be/UIgv7VRP_S0 Video if you have any problem with this tutorial. Please subscribe to our channel and share this tutorial.