使 Wordpress 页面的标题只读 [英] Make Wordpress Pages's Titles readonly

查看:32
本文介绍了使 Wordpress 页面的标题只读的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找一个 WP 函数,它将只读参数添加到所有页面的标题的输入中,这将使页面的标题不可更改.

I'm looking for a WP function that add the Read-only parameter to all Pages's Titles's input, that will make the Page's title unalterable.

非常感谢.

推荐答案

这可以通过一些简单的 JavaScript/jQuery 来完成.创建一个名为 admin_title_disable.js 的文件,并将其放入 functions.php 中.例如:

This can be accomplished with some simple JavaScript/jQuery. Create a file called admin_title_disable.js, and queue it up within functions.php. For example:

functions.php:

functions.php:

wp_register_script('admin_title_disable', '/path/to/admin_title_disable.js');
function disableAdminTitle () {
  wp_enqueue_script('admin_title_disable');
}
add_action('admin_enqueue_scripts', 'disableAdminTitle');

现在,在您的 js 文件中:

Now, in your js file:

jQuery(document).ready(function ($) {
  $('#title').attr('disabled','disabled');
});

这将使用 disabled 属性设置帖子和页面标题输入字段.希望这会有所帮助!

This will set both post and page title input fields with a disabled attribute. Hope this helps!

如果您想将此脚本限制为特定的管理页面,请将 add_action 钩子包装在比较 $_GET['page'] 的条件中.您还可以利用在使用 admin_enqueue_scripts 时可用的 $hook 参数来检查页面.参见此处.

If you want to restrict this script to a particular admin page, wrap the add_action hook in a conditional that compares $_GET['page']. You can also take advantage of the $hook parameter that is available when using admin_enqueue_scripts to check for the page. See here.

更新::

WordPress 使得区分帖子和页面编辑屏幕有点棘手,但您可以利用一个隐藏的输入.:) 这是 jQuery 的更新版本,它只能在页面编辑屏幕上运行:

WordPress makes it a little tricky to tell between post and page edit screens, but there is a hidden input that you can take advantage of. :) Here's an updated version of the jQuery that will only run on page edit screens:

jQuery(document).ready(function ($) {
  //find the hidden post type input, and grab the value
  if($('#post_type').val() === 'page'){
    $('#title').attr('disabled','disabled');
  }
 });

这篇关于使 Wordpress 页面的标题只读的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆