开发者

Wordpress : Add a custom field directly above the title input field (w/o modifiying core files)?

开发者 https://www.devze.com 2023-01-14 19:51 出处:网络
Does anyone know of a way to add an input field (or any type of html for the matter) directly above (or below) the title input field on the post ed开发者_如何学Cit page ?

Does anyone know of a way to add an input field (or any type of html for the matter) directly above (or below) the title input field on the post ed开发者_如何学Cit page ?

I'm looking of a way to do this without modifying core files (I'm doing this as part of a plug-in which creates a custom post-type).

I'm not aware of any available wp hooks in that area of the edit-form-advanced.php file which could help out. I really hope some has come up with a genius workaround !


Since version 3.5 wordpress introduced new hooks for the add/edit post screen called edit_form_after_title and edit_form_after_editor. So now i think we can easily add new html element after wordpress input title and input content.

just use filter like this on your 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>';
}


You're on the right track; pursue the add_action('admin_head') point of entry. What you want can specifically be done with a bit of JavaScript + jQuery (which is built into WP). To display the input field above the title input field, do something like this:

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
}

And you should be seeing something like this:

Wordpress : Add a custom field directly above the title input field (w/o modifiying core files)?

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号