edit_form_after_editor only in post edit pages

I want to show some information in post edit screen. I found 2 hooks which allow to do this after title or after editor. Heres code with second one:

add_action( 'edit_form_after_editor', 'myprefix_edit_form_after_editor' );
function myprefix_edit_form_after_editor() {
    global $post;
    $author_id=$post->post_author;
    $email = get_the_author_meta( 'user_email', $author_id);
    $imie = get_the_author_meta( 'first_name', $author_id);
    $nazwisko = get_the_author_meta( 'last_name', $author_id);
    $nip = get_the_author_meta( 'nip', $author_id);
    $login = get_the_author_meta( 'user_login', $author_id);
    $firma = get_the_author_meta( 'nazwa_firmy', $author_id);
    echo '<h1>DANE FIRMY</h1>';
    echo '<strong>Nazwa firmy: </strong>', $firma;
    echo '<br><strong>Imię: </strong>', $imie;
    echo '<br><strong>Nazwisko: </strong>', $nazwisko;
    echo '<br><strong>NIP: </strong>', $nip;
    echo '<br><strong>E-mail: </strong>', $email;
    echo '<br><strong>Login: </strong>', $login,'<br><br>';
}

I want this information to show only on post edit pages – now it shows everywhere (custom post type edit pages, pages edit screens etc.).

Read More

Maybe theres hook which allows to show this info under featured image (right part of edit screen).

Related posts

1 comment

  1. Often with WP, it really helps to actually locate where and how a hook is called before using it.

    If you search the code base for edit_form_after_editor, you’ll locate:

    /**
     * Fires after the content editor.
     *
     * @since 3.5.0
     *
     * @param WP_Post $post Post object.
     */
    do_action( 'edit_form_after_editor', $post );
    

    As you can see, $post is actually passed as an argument here. To access and use it without any chance of error, pass it to your function:

    function myprefix_edit_form_after_editor($post) {
        var_dump($post);
    

    To weed out non-posts, just go something like:

    function myprefix_edit_form_after_editor($post) {
        if ($post->post_type != 'post') return;
    

Comments are closed.