注册表的占位符文本

时间:2014-01-22 作者:mr_bythatmuch

我正在尝试将占位符文本添加到本机WordPress注册表中。我目前正在使用Register Plus Redux插件。如何将此占位符文本添加到表单的文本输入字段中?

我需要告诉人们使用他们的名字和姓氏作为用户名。如果有人能帮我,我会很兴奋的。

2 个回复
SO网友:renzo_cast

另一种不需要添加其他脚本的简单方法是使用PHP的str_replace 作用

$args = array(
    \'echo\' => false,
);

$form = wp_login_form( $args ); 

//add the placeholders
$form = str_replace(\'name="log"\', \'name="log" placeholder="Username"\', $form);
$form = str_replace(\'name="pwd"\', \'name="pwd" placeholder="Password"\', $form);

echo $form;

SO网友:Maruti Mohanty

遗憾的是,没有钩子/过滤器可以修改登录/注册表单中的输入字段以向其添加占位符。

但您可以通过简单的jQuery来实现这一点。我正在添加以下步骤

我不知道这个插件是如何改变表单的,但你也可以遵循同样的方法。以下是用于默认登录/注册页面的代码

首先,您需要创建一个js文件。我在我的active theme\'s js folder 并给它命名custom.js

然后在此文件中添加以下行。

/**
 * Custom js file.
 */

jQuery(document).ready(function(){
    jQuery(\'#user_login\').attr(\'placeholder\', \'User Name\');
    jQuery(\'#user_email\').attr(\'placeholder\', \'User Email\');
    jQuery(\'#user_pass\').attr(\'placeholder\', \'User Password\');
});
上述内容将占位符添加为User Name, User EmailUser Passworduser_login, user_email, 和user_pass 分别输入字段。您可以根据您的要求进行更改。

现在您需要添加/排队这个js文件,您可以通过在活动主题的functions.php 文件

add_action( \'login_enqueue_scripts\', \'wpse_login_enqueue_scripts\', 10 );
function wpse_login_enqueue_scripts() {
    wp_enqueue_script( \'custom.js\', get_template_directory_uri() . \'/js/custom.js\', array( \'jquery\' ), 1.0 );
}

结束

相关推荐