Add a button / link immediately after the header to a custom message type edit screen

I am setting up the server side of the WordPress installation for the client, and I have added some custom post types. They are displayed in the interface through a custom loop within the same page, so users should not access individual user messages.

To ensure that they are not accidentally available, I removed the Permalink selection box, which includes the "Show Message" button. I would like to add a “View Post” link at the top of the page, next to “Add a new employee.” (If this is not possible, I would agree to intercept and replace the "Add a new employee" button).

I'm looking for a WordPress hook to place a button there, but I haven't found anything yet. The closest thing that I have found - this blog post WP Core (citing , , ), but none of these will not work for this. edit_form_advancededit_form_after_editoredit_form_after_title

The button I would like to add would be this PHP:

<a class="add-new-h2" href="<?php echo $displaypage.get_the_title($post_ID); ?>">View <?php echo $posttype; ?></a>

C $displaypagewill be something like strings'/about-us/our-people/#'

In fact, all I need is to find a way to connect it. I know what to add as soon as I learn how to add it.

Test

Edit:

, , javascript, - . , , , JS, (jQuery , , ).

+4
2

, WP Core :

enter image description here

, Add New (post type) <h2> ( 365 ), .

add_action( 'edit_form_top', 'top_form_edit' );

function top_form_edit( $post ) {
    if( 'portfolio' == $post->post_type )
        echo "<a href='#' id='my-custom-header-link'>$post->post_type</a>";
}

- DOM jQuery:

add_action( 'admin_head-post.php', 'manipulate_dom' );
add_action( 'admin_head-post-new.php', 'manipulate_dom' );

function manipulate_dom()
{
    // Not our post type, exit earlier
    // Adjust post type
    if( 'portfolio' != get_current_screen()->post_type )
        return;
    ?>
    <script type="text/javascript">
        jQuery(document).ready( function($) 
        {
            // your thing
            // $('#my-custom-header-link').moveAround();        
        });     
    </script>
    <?php 
}
+3

, , :

  • 'admin_notices'
  • CSS, :

            function rewrite_cpt_header(){
                  $screen = get_current_screen();
                if( $screen->id !='edit-location' ){
                    return;
                } else {
                    ?>
                    <div class="wrap">
                    <h1 class="wp-heading-inline show" style="display:inline-block;">Locations</h1>
                    <a href="<?php echo admin_url('post-new.php?post_type=location'); ?>" class="page-title-action show">Add New Location</a>
                    <a href="<?php echo admin_url('edit-tags.php?taxonomy=location_types&post_type=location'); ?>" class="page-title-action show">Edit Location Types</a>
                    </div>
    
                    <style scoped>
                    .wp-heading-inline:not(.show),
                    .page-title-action:not(.show) { display:none !important;}
                    </style>
                    <?php
                }
             }
             add_action('admin_notices','rewrite_cpt_header');
    
+1

Source: https://habr.com/ru/post/1530690/


All Articles