כדי לשתף עמודים ופוסטים בלי לקבל לינק ארוך תוסיפו את הבא ותקבלו את הלינק המקוצר, את הלינק תוכלו לראות בסרגל הניהול של וורדפרס, לחיצה עם קליק ימני תוכלו להעתיק את הלינק המקוצר ולשתף.
PHP
// Display Shortlink in Navigation Bar
function display_shortlink_in_navbar( $wp_admin_bar ) {
global $wp;
// Get the current URL
$current_url = home_url( add_query_arg( array(), $wp->request ) );
// Check if it's an archive page
if ( is_archive() ) {
// Get the current queried object
$queried_object = get_queried_object();
// Check if it's a taxonomy archive
if ( is_tax() || is_category() || is_tag() ) {
// Get the term link for the current taxonomy term
$term_link = get_term_link( $queried_object );
$shortlink = esc_url( $term_link );
} else {
$shortlink = esc_url( $current_url );
}
} else {
// Get the current post/page ID
$post_id = get_the_ID();
// Get the shortlink of the current post/page
$shortlink = wp_get_shortlink( $post_id );
}
// Add the shortlink to the admin bar
$wp_admin_bar->add_menu( array(
'id' => 'shortlink',
'title' => 'Shortlink',
'href' => $shortlink,
) );
}
add_action( 'admin_bar_menu', 'display_shortlink_in_navbar', 999 );