4

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

我正在寻找一种在不修改核心文件的情况下执行此操作的方法(我将其作为创建自定义帖子类型的插件的一部分)。

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

4

2 回答 2

8

从 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>';
}
于 2015-06-11T08:47:04.627 回答
2

你在正确的轨道上;追求 add_action('admin_head') 入口点。你想要的可以通过一点 JavaScript + jQuery(内置于 WP)来完成。要在标题输入字段上方显示输入字段,请执行以下操作:

add_action('admin_head', 'my_admin_head_in_posts');
function my_admin_head_in_posts() {
?>
jQuery('#post').before(
'<div id="id_my_field" class="updated below-h2">' +
'<input type="text" name="my_field" value="lol" />' + 
'</div>'
);
<?php
}

你应该会看到这样的东西: 替代文字

于 2010-09-02T19:32:27.167 回答