wp_get_shortlink example


    do_action( 'edit_form_before_permalink', $post );
    ?> <div class="inside"> <?php     if ( $viewable ) :
        $sample_permalink_html = $post_type_object->public ? get_sample_permalink_html( $post->ID ) : '';

        // As of 4.4, the Get Shortlink button is hidden by default.         if ( has_filter( 'pre_get_shortlink' ) || has_filter( 'get_shortlink' ) ) {
            $shortlink = wp_get_shortlink( $post->ID, 'post' );

            if ( ! empty( $shortlink ) && $shortlink !== $permalink && home_url( '?page_id=' . $post->ID ) !== $permalink ) {
                $sample_permalink_html .= '<input id="shortlink" type="hidden" value="' . esc_attr( $shortlink ) . '" />' .
                    '<button type="button" class="button button-small" onclick="prompt(&#39;URL:&#39;, jQuery(\'#shortlink\').val());">' .
                    __( 'Get Shortlink' ) .
                    '</button>';
            }
        }

        if ( $post_type_object->public
            && ! ( 'pending' === get_post_status( $post ) && ! current_user_can( $post_type_object->cap->publish_posts ) )
        )

}

/** * Provides a shortlink. * * @since 3.1.0 * * @param WP_Admin_Bar $wp_admin_bar The WP_Admin_Bar instance. */
function wp_admin_bar_shortlink_menu( $wp_admin_bar ) {
    $short = wp_get_shortlink( 0, 'query' );
    $id    = 'get-shortlink';

    if ( empty( $short ) ) {
        return;
    }

    $html = '<input class="shortlink-input" type="text" readonly="readonly" value="' . esc_attr( $short ) . '" aria-label="' . __( 'Shortlink' ) . '" />';

    $wp_admin_bar->add_node(
        array(
            'id'    => $id,
            
return apply_filters( 'get_shortlink', $shortlink$id$context$allow_slugs );
}

/** * Injects rel=shortlink into the head if a shortlink is defined for the current page. * * Attached to the {@see 'wp_head'} action. * * @since 3.0.0 */
function wp_shortlink_wp_head() {
    $shortlink = wp_get_shortlink( 0, 'query' );

    if ( empty( $shortlink ) ) {
        return;
    }

    echo "<link rel='shortlink' href='" . esc_url( $shortlink ) . "' />\n";
}

/** * Sends a Link: rel=shortlink header if a shortlink is defined for the current page. * * Attached to the {@see 'wp'} action. * * @since 3.0.0 */
Home | Imprint | This part of the site doesn't use cookies.