• Hi,

    How do i get infield labels for the standard WP comment form? I want to get the labels inside the input field but don’t have a clue how. Searched for almost 3 hours and can’t find a good solution. I found different sites with solutions how to do it but NOT for wordpress. (i’m not a top of the top developer). Can someone please help me?

    Thanks in advance!

Viewing 3 replies - 1 through 3 (of 3 total)
  • Moderator bcworkz

    (@bcworkz)

    Do you mean a placeholder like the “Search www.ads-software.com” in this site’s search box? Or the disappearing label like in the twentyeleven theme comment form?

    Either way you probably need to tweak the form HTML by hooking the ‘comment_form_default_fields’ filter. Your callback is passed an array where each element is the HTML for a field. The comment field itself has its own filter, ‘comment_form_field_comment’.

    The placeholder is a HTML5 attribute, just add it to the input or textarea tag. I believe the twentyeleven thing is a regular label placed by CSS and the display CSS is toggled between none and inline with javascript onfocus and onblur.

    Thread Starter eazy4me

    (@eazy4me)

    Yes i mean a placeholder like the “Search www.ads-software.com” in this site’s search box. I’m a little bit of a rookie in programming so i realy don’t know exactly what your saying. Can you please tell me what to tweak exactly?

    Moderator bcworkz

    (@bcworkz)

    Read about hooking actions and filters in the Plugin API. The technique is fundamental to customizing anything in WordPress. Once you hook into the filters I mentioned previously, your callback function is passed the comment field HTML. Use PHP string manipulation to insert something like placeholder="my label" into the input tags. A typical comment field should end up looking like something like this when you’re done: <input id="author" name="author" type="text" value="" size="30" placeholder="my label" />. Then return the modified HTML data.

    When developing string manipulation code I usually var_dump the value passed to my callback. I then copy it into a simple PHP test page where I can easily develop the correct code to do what’s needed without the distraction of all the other WordPress stuff. Once the code is working right, I can insert it into my filter callback function with confidence that it will work correctly.

    Even though the article is about plugin development, you can place code that hooks into WordPress in your theme’s or better yet your child theme’s functions.php file. Or you might consider starting a “catch all” plugin that contains all of your future little customizing code.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘How to get infield labels for comment form’ is closed to new replies.