How To Add New Records To A User In WordPress

If you’re using a content management system for your website, you have the option to have more than one user within the system. If, for instance, you have an entire editorial team, it’s likely composed of numerous members. All of them probably have their profiles created within WordPress, through which they access the system. WordPress itself requires several essential things for user registration: a username, password, and email address. Optionally, you can also fill in the first and last name. However, what if you need to have more such information for users, such as a phone number, Facebook, or Twitter? Using a small snippet, you can easily add these items to a user. In this article, we’ll show you how to add new records to a user in WordPress, and this is a very secure and straightforward process.

How To Add New Records To A User In WordPress

To avoid installing an additional plugin for these purposes, we’ll use a snippet and the popular WPCode plugin, which should be installed by anyone looking to customize their WordPress website’s properties and behaviors. A snippet is nothing more than a short piece of code in PHP or another language that alters the properties and behavior of the website.

Installing the WPCode plugin

To insert codes into your website, you have two options. You can hardcode the code into the file where it belongs, or you can use a plugin that dynamically inserts portions of the code into the website during its operation. The second option is better for one simple reason: it’s safer, and your code won’t be erased with each update that overwrites the file containing your code.

Here are the steps to install the WPCode plugin:

  • Click on ‘Plugins‘ in the left menu.
  • Choose ‘Add New‘ in the submenu.
  • Notice the search field in the top right corner.
  • Type in the key phrase ‘WPCode‘.
  • Once WordPress finds the plugin, install and activate it.

If you’re interested in a complete article where I describe working with this plugin, check it out here: How to insert custom codes into WordPress.

Jak do WordPressu vkládat vlastní kódy

Snippet for additional user fields

Using the WPCode plugin mentioned above, insert the following snippet into your website:

				
					//blog.jirivanek.eu - Custom fields snippet
function new_contactmethods( $contactmethods ) {
// Add Twitter
$contactmethods['twitter'] = 'Twitter account';
//add Facebook
$contactmethods['facebook'] = 'Facebook  account';
//add Phone
$contactmethods['Phone'] = 'Phone  number';
 
return $contactmethods;
}
add_filter('user_contactmethods','new_contactmethods',10,1);
				
			

This short code adds new fields for users to input their Facebook address, Twitter handle, and phone number. Moreover, you can modify the snippet according to your needs. For instance, by adding the line below into the code, you’ll expand the user profile to include the option to input a LinkedIN profile address as well.

				
					//add LinkedIN
$contactmethods['LinkedIN'] = 'LinkedIN';
				
			
Jak přidat nové záznamy k uživateli ve WordPressu

So, as you can see, the possibilities are unlimited. You can add as many fields as needed based on the information you require from users.

How To Add New Records To A User In WordPress

Conclusion

In this example, we’ve demonstrated how you can efficiently add additional functionalities to WordPress in a completely secure manner. However, before making any modifications to the internal code of WordPress, even with the help of snippets and the WPCode plugin, I recommend you always create your own backup. This way, you can revert to it at any time in case of issues.

The website is created with care for the included information. I strive to provide high-quality and useful content that helps or inspires others. If you are satisfied with my work and would like to support me, you can do so through simple options.

Byl pro Vás tento článek užitečný?

Klikni na počet hvězd pro hlasování.

Průměrné hodnocení. 0 / 5. Počet hlasování: 0

Zatím nehodnoceno! Buďte první

Jak užitečný vidíte tento článek.

Sledujte mě na sociálních médiích.

Je mi líto, že pro Vás nebyl článek užitečný.

Jak mohu vylepšit článek?

Řekněte mi, jak jej mohu zlepšit.

newsletter

Subscribe to the Newsletter

Stay informed! Join our newsletter subscription and be the first to receive the latest information directly to your email inbox. Follow updates, exclusive events, and inspiring content, all delivered straight to your email.

Odebírat
Upozornit na
guest
0 Komentáře/ů
Nejstarší
Nejnovější Nejvíce hlasováno
Vložené zpětné vazby.
Zobrazit všechny komentáře.

Pokud mi chcete napsat rychlou zprávu, využije, prosím, níže uvedený
kontaktní formulář. Děkuji.

Další Kontaktní údaje