Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save dwanjuki/e2535e869e1a1415f7a408aaf2fe0076 to your computer and use it in GitHub Desktop.
Save dwanjuki/e2535e869e1a1415f7a408aaf2fe0076 to your computer and use it in GitHub Desktop.
Add placeholder HTML attribute to PMPro user fields
<?php
/**
* Add placeholder HTML attribute to PMPro user fields.
*
* You can add this recipe to your site by creating a custom plugin
* or using the Code Snippets plugin available for free in the WordPress repository.
* Read this companion article for step-by-step directions on either method.
* https://www.paidmembershipspro.com/create-a-plugin-for-pmpro-customizations/
*/
function my_pmpro_user_fields_add_placeholder( $field, $where ) {
$placeholder = '';
switch ( $field->name ) {
case 'my_field':
$placeholder = 'Placeholder for field named my_field';
break;
case 'another_field':
$placeholder = 'Placeholder for field named another_field';
break;
case 'field_3':
$placeholder = 'Placeholder for field named field_3';
break;
}
if ( $placeholder ) {
$field->html_attributes = array(
'placeholder' => $placeholder,
);
}
return $field;
}
add_filter( 'pmpro_add_user_field', 'my_pmpro_user_fields_add_placeholder', 10, 2 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment