WordPress:在标题输入字段的正上方添加一个自定义字段(不修改核心文件)吗?

sct*_*ham 4 wordpress custom-fields

有谁知道在帖子编辑页面的标题输入字段正上方(或下方)添加输入字段(或与此类型的任何类型的html)的方法吗?

我正在寻找一种无需修改核心文件的方法(我将其作为创建自定义帖子类型的插件的一部分来进行)。

我不知道在edit-form-advanced.php文件的该区域中是否有任何可用的wp钩子可以帮助您。我真的希望有人提出了一个天才的解决方法!

Laf*_*ziq 6

从3.5版开始,wordpress引入了用于添加/编辑发布屏幕的新钩子,称为edit_form_after_titleedit_form_after_editor。所以现在我认为我们可以在wordpress输入标题和输入内容之后轻松添加新的html元素。

像这样在你的过滤器 functions.php

add_action( 'edit_form_after_title', 'my_new_elem_after_title' );
function my_new_elem_after_title() {
    echo '<h2>Your new element after title</h2>';
}

add_action( 'edit_form_after_editor', 'my_new_elem_after_editor' );
function my_new_elem_after_editor() {
    echo '<h2>Your new element after content</h2>';
}
Run Code Online (Sandbox Code Playgroud)