Adding More Data to Your Comments Using Hooks

We can even add fields to the comment for using the ‘comment_form_default_fields‘ filter. Now let’s add a comment author’s age field using this filter and then store this field as a comment meta and display it on the comment.

We can add a field as follows:

Once we add the field depending on the theme we might want to style it. As I am using the Twenty Eleven theme I style it by adding #respond .comment-form-age label with the other labels style like #respond .comment-form-url label etc. as follows:

Now if we see the comment form the age field will be seen as follows:

Now that the age is stored as the comment meta we need to hook into ‘comment_post‘ and save the age as comment meta as follows:

Once the meta is saved it can be displayed on the comment as follows:–wp-26128
5 سال پیش

دیدگاهتان را بنویسید

نشانی ایمیل شما منتشر نخواهد شد. بخش‌های موردنیاز علامت‌گذاری شده‌اند *

این سایت از اکیسمت برای کاهش هرزنامه استفاده می کند. بیاموزید که چگونه اطلاعات دیدگاه های شما پردازش می‌شوند.