Trusted WordPress tutorials, when you need them most.
Beginner’s Guide to WordPress
WPB Cup
25 Million+
Websites using our plugins
16+
Years of WordPress experience
3000+
WordPress tutorials
by experts

Så här visar du användarens registreringsdatum i WordPress

Vill du visa användarens registreringsdatum i WordPress? Ofta visar populära membership sites och forum användarens registreringsdatum i profilen som ”medlem sedan 2015”. I den här artikeln kommer vi att täcka hur man visar användarens registreringsdatum i WordPress.

Showing a the date of a user's registration in WordPress

Var och hur vill du visa användarens registreringsdatum?

En del av er kanske bara vill displayed en användares registreringsdatum i admin columns på Users page. Detta ger you en snabb överblick över när en användare gick med på your website och allow you att sortera efter registreringsdatum.

Ett annat användningsscenario är att visa en användares registreringsdatum på sidan ”Edit Profile”. This will allow any administrator and the user themselves to see when they joined your website.

Sist men förmodligen det mest populära användningsscenariot är när du vill visa användarens registreringsdatum på deras offentliga profil på front end på din website.

Låt oss ta en titt på hur du kan göra dem alla.

Lägga till kolumnen Registrerat datum på sidan Användare i Admin Area

Det första du behöver göra är att installera och aktivera pluginet Admin Columns. Efter aktivering måste du besöka Settings ” Admin Columns för att konfigurera pluginet.

Add registered column in users table

Under admin columns tabs, klicka på användare och klicka sedan på add column knappen.

Välj sedan ”Registered” i rullgardinsmenyn Typ och klicka på knappen Store updates.

Du kan nu besöka vyn Användare där du kommer att se en new column märkt ”Registrerad” som visar det datum då en användare registrerade sig på din WordPress site.

Users table with registration date column

Se vilka andra saker du kan göra för att add to och customize admin columns i WordPress.

Visa fältet för registreringsdatum i användarens profil

För att visa registreringsdatum på sidan edit profile måste du uploada ett custom plugin till din website.

Skapa helt enkelt en new fil på din dator med hjälp av en textredigerare som Notepad och save den som membersince.php på ditt skrivbord.

Öppna sedan filen och klistra in följande kod i den.

<?php
/*
Plugin Name: Member Since
Plugin URI:  https://www.wpbeginner.com
Description: Adds registration date on edit user profile screen. 
Version:     1.0
Author:      WPBeginner
*/


namespace ShowMemberSince;
add_action( 'plugins_loaded', 'ShowMemberSince\init' );
/**
 * Adding needed action hooks
*/
function init(){
  foreach( array( 'show_user_profile', 'edit_user_profile' ) as $hook )
		add_action( $hook, 'ShowMemberSince\add_custom_user_profile_fields', 10, 1 );
}
/**
 * Output table
 * @param object $user User object
 */
function add_custom_user_profile_fields( $user ){
	$table =
	'<h3>%1$s</h3>
	<table class="form-table">
		<tr>
			<th>
				%1$s
			</th>
			<td>
				<p>Member since: %2$s</p>
			</td>
		</tr>
	</table>';
	$udata = get_userdata( $user->ID );
	$registered = $udata->user_registered;
	printf(
		$table,
		'Registered',
		date( "M Y", strtotime( $registered ) )
	);
}
?>

Save your file and then upload it to your WordPress site.

Slutligen kan du ansluta till din WordPress site med hjälp av en FTP-klient och sedan gå till /wp-content/plugins/ folder. Välj filen membersince.php från din dator och uppladare den sedan.

Nu kan du gå till din WordPress plugins page och aktivera detta plugin på din website.

Det var allt. Kontrollera att allt fungerar genom att edit en användares profil på i din WordPress admin area, och du kommer att se användarens registreringsdatum.

Showing member registration date in WordPress user profile

Visa användarens registreringsdatum på din website

I den här metoden kommer vi att använda en enkel shortcode för att visa alla användares registreringsdatum på front-end av din WordPress webbplats.

Först måste du add to följande kod i ditt temas functions.php-fil eller i ett site-specifikt plugin.


function wpb_user_registration_date($atts, $content = null ) { 

$userlogin = shortcode_atts( array(
'user' => FALSE,
), $atts );

$uname = $userlogin['user'];     

if ($uname!== FALSE) {             

$user = get_user_by( 'login', $uname );  
if ($user == false) { 

$message ='Sorry no such user found.'; 


} else { 

$udata = get_userdata( $user-ID );
$registered = $udata->user_registered;

$message =	'Member since: ' . date( "d F Y", strtotime( $registered ) );

}
	
} else { 

$message = 'Please provide a username.'; 

} 

return $message; 

} 

add_shortcode('membersince', 'wpb_user_registration_date');

Därefter kan du visa en användares registreringsdatum genom att helt enkelt använda shortcode så här:

[membersince user=peter]

Ersätt peter med användarnamnet som du vill visa.

Vi hoppas att den här artikeln hjälpte dig att visa registreringsdatum i WordPress användares profiler. Du kanske också vill se vår tutorial om hur du lägger till ytterligare fält för användarprofiler i WordPress-registrering.

Om du gillade den här artikeln, vänligen prenumerera på vår YouTube-kanal för WordPress video tutorials. Du kan också hitta oss på Twitter och Facebook.

Avslöjande: Vårt innehåll stöds av våra läsare. Det innebär att om du klickar på några av våra länkar, kan vi tjäna en provision. Se hur WPBeginner finansieras, varför det är viktigt, och hur du kan stödja oss. Här är vår editoriala process.

Avatar

Editorial Staff at WPBeginner is a team of WordPress experts led by Syed Balkhi with over 16 years of experience in WordPress, Web Hosting, eCommerce, SEO, and Marketing. Started in 2009, WPBeginner is now the largest free WordPress resource site in the industry and is often referred to as the Wikipedia for WordPress.

Den ultimata WordPress-verktygslådan

Få GRATIS tillgång till vår verktygslåda - en samling WordPress-relaterade produkter och resurser som varje professionell användare bör ha!

Reader Interactions

18 kommentarerLämna ett svar

  1. Syed Balkhi says

    Hey WPBeginner readers,
    Did you know you can win exciting prizes by commenting on WPBeginner?
    Every month, our top blog commenters will win HUGE rewards, including premium WordPress plugin licenses and cash prizes.
    You can get more details about the contest from here.
    Start sharing your thoughts below to stand a chance to win!

  2. Tom says

    Hello :) Nice code thank you but is it possible with the shortcode to show the register date of the user which actually logged in?

  3. Ralph says

    TYPO: There is one typo in the code in method 3 that results in the error of date always showing the same value: On line 37 is
    $udata = get_userdata( $user-ID );

    while it should be:
    $udata = get_userdata( $user->ID );

    (Notice the arrow instead of the dash)

  4. chergui djaouida says

    please i need to introduce the date of registration of a user in a php code not by a shortcode how to do?

  5. Isabelle Laplante says

    «Showing Registration Date Field in User Profile» costum Plugin works but do not show the real date… For every users, the added information is«Member since: Jun 2015» … Wich is not the case… Can you help?

  6. Jody Hockley says

    Hi,

    Thanks for the plugin, nice easy fix for a simple problem.

    I have just used the second option to show in the User profile page. However it only show month and year, not the day. How would I alter the plugin code to show the day too?

    Thanks for your help, much appreciated

    Jody

  7. Gerard says

    Very nice :).
    I needed only first code snippet (which works).
    Just one little note: on line 37 you should make it ’$user->ID” you forgot the ’>’, else it shows notices when debuggin.

    Thank you.

  8. Davis says

    Admin Columns plugin developer requires $60US to sort by registration date. If you are a site manager, find a better solution. WP should include this ultra-basic functionality in all WP installs.

  9. Hemang Rindani says

    Insightful article. WordPress is the most user friendly CMS that can create complex websites with very less or no technical knowledge. It comes with rich set of modules and plugins that can transform your digital dream into a reality. However, it is important to identify the secured and authenticated tools for your WordPress website to improve the overall website security. WP is capable of handling multiple sites with multiple users which has been a requirement of big organizations. WP provides some great features to manage user accounts and prevent the website from unauthorized access using certain plugins with your website. There are also tools to enhance the user experience like the one described in the article to provide a great personal feel to the user.

    Thanks for the article.

  10. Patrick Catthoor says

    This looked like a feature I could use for my website. So, I tried all 3 methods.
    Method 1 works like a charm, but both methods 2 and 3 always provide the same date: 01 January 1970. Something must be wrong, but I couldn’t figure out what.
    Any ideas?

    • Celito C. Macachor says

      I realize this is an old issue, but I just came across this article after a recent search. Great, insightful articles, but I have the same concern as Patrick’s. In the all users list, the registration date is correct. While it is not critical, only one date (July 2016) is shown for all users in the Member since field. Has this issue been resolved? Thanks for any updated information.

Lämna ett svar

Tack för att du väljer att lämna en kommentar. Tänk på att alla kommentarer modereras enligt våra policy för kommentarer, och din e-postadress kommer INTE att publiceras. Vänligen använd INTE nyckelord i namnfältet. Låt oss ha en personlig och meningsfull konversation.