html只显示姓隐藏名字,#wordpress如何隐藏掉last-name姓氏和first-name名字两个字段

主要参考:Link

在对应的主题文件夹下的functions.php文件中,例如:wp-content\themes\vt-blogging\functions.php中

参考原文说明

// Function to disable the first name and last name fields

function disable_first_and_last_name_fields() {

?>

$(function() {

// Disable the first and last names in the admin profile so that user‘s cannot edit these

$(‘#first_name‘).prop( ‘disabled‘, true );

$(‘#last_name‘).prop( ‘disabled‘, true );

});

}

// Action hook to inject the generated JavaScript into admin pages

add_action( ‘admin_head‘, ‘disable_first_and_last_name_fields‘ );

wordpress是自带jQuery的,这里,作者通过wordpress的action钩子注入了一段jQuery脚本,该脚本的作用就是,通过css把相关的dom节点的disable属性设定为true。

最后的实现

注意,如果直接这么把代码贴过去,是不会生效的,需要把$换成jQuery关键字。详细的原因,见这里.

我更希望直接把这个dom通过css移除掉,所以最后我的解决方式是:

/* 隐藏掉姓氏和名字两个字段 */

// Function to disable the first name and last name fields

function disable_first_and_last_name_fields() {

?>

let $ = jQuery;

$(function() {

// Disable the first and last names in the admin profile so that user‘s cannot edit these

$(‘.user-first-name-wrap‘).css( ‘display‘, ‘none‘ );

$(‘.user-last-name-wrap‘).css( ‘display‘, ‘none‘ );

});

}

// Action hook to inject the generated JavaScript into admin pages

add_action( ‘admin_head‘, ‘disable_first_and_last_name_fields‘ );

20200704154819315161.png

如果需要自定义脚本然后从functions.php中去引入,参见这里

原文:https://www.cnblogs.com/jaycethanks/p/13235061.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
以下是一个简单的 WordPress 显示SVIP1 - 10会员等级图标功能代码: 1. 创建一个自定义用户角色,可以使用现有的角色,也可以创建新的角色: ``` add_role( 'svip1', 'SVIP1', array( 'read' => true ) ); add_role( 'svip2', 'SVIP2', array( 'read' => true ) ); add_role( 'svip3', 'SVIP3', array( 'read' => true ) ); add_role( 'svip4', 'SVIP4', array( 'read' => true ) ); add_role( 'svip5', 'SVIP5', array( 'read' => true ) ); add_role( 'svip6', 'SVIP6', array( 'read' => true ) ); add_role( 'svip7', 'SVIP7', array( 'read' => true ) ); add_role( 'svip8', 'SVIP8', array( 'read' => true ) ); add_role( 'svip9', 'SVIP9', array( 'read' => true ) ); add_role( 'svip10', 'SVIP10', array( 'read' => true ) ); ``` 2. 在主题的 functions.php 文件中添加一个函数来获取当前用户的角色: ``` function get_user_role() { $user = wp_get_current_user(); $roles = (array) $user->roles; return $roles[0]; } ``` 3. 在需要显示会员等级的地方,添加以下代码: ``` <?php $user_role = get_user_role(); ?> <?php if ( $user_role == 'svip1' ) : ?> <img src="<?php echo get_stylesheet_directory_uri() . '/images/svip1.png'; ?>" alt="SVIP1"> <?php elseif ( $user_role == 'svip2' ) : ?> <img src="<?php echo get_stylesheet_directory_uri() . '/images/svip2.png'; ?>" alt="SVIP2"> <?php elseif ( $user_role == 'svip3' ) : ?> <img src="<?php echo get_stylesheet_directory_uri() . '/images/svip3.png'; ?>" alt="SVIP3"> <?php elseif ( $user_role == 'svip4' ) : ?> <img src="<?php echo get_stylesheet_directory_uri() . '/images/svip4.png'; ?>" alt="SVIP4"> <?php elseif ( $user_role == 'svip5' ) : ?> <img src="<?php echo get_stylesheet_directory_uri() . '/images/svip5.png'; ?>" alt="SVIP5"> <?php elseif ( $user_role == 'svip6' ) : ?> <img src="<?php echo get_stylesheet_directory_uri() . '/images/svip6.png'; ?>" alt="SVIP6"> <?php elseif ( $user_role == 'svip7' ) : ?> <img src="<?php echo get_stylesheet_directory_uri() . '/images/svip7.png'; ?>" alt="SVIP7"> <?php elseif ( $user_role == 'svip8' ) : ?> <img src="<?php echo get_stylesheet_directory_uri() . '/images/svip8.png'; ?>" alt="SVIP8"> <?php elseif ( $user_role == 'svip9' ) : ?> <img src="<?php echo get_stylesheet_directory_uri() . '/images/svip9.png'; ?>" alt="SVIP9"> <?php elseif ( $user_role == 'svip10' ) : ?> <img src="<?php echo get_stylesheet_directory_uri() . '/images/svip10.png'; ?>" alt="SVIP10"> <?php endif; ?> ``` 这些代码仅供参考,您需要将其修改为适合您的主题和需求的代码。另外,您还需要在主题中添加相应的图片,用于显示会员等级图标。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值