$is_external_permalink_enabled ) { if ( ( get_post_type() == $post_type_slug ) && $is_external_permalink_enabled ) { // Skip adding meta box for post types where Gutenberg is enabled // if ( // function_exists( 'use_block_editor_for_post_type' ) // && use_block_editor_for_post_type( $post_type_slug ) // ) { // continue; // go to the beginning of next iteration // } add_meta_box( 'asenha-external-permalink', // ID of meta box 'External Permalink', // Title of meta box [ $this, 'output_external_permalink_meta_box' ], // Callback function $post_type_slug, // The screen on which the meta box should be output to 'normal', // context 'high' // priority // array(), // $args to pass to callback function. Ref: https://developer.wordpress.org/reference/functions/add_meta_box/#comment-342 ); } } } /** * Render External Permalink meta box * * @since 3.9.0 */ public function output_external_permalink_meta_box( $post ) { ?> ID, '_links_to', true ); if ( ! empty( $external_permalink ) ) { $permalink = $external_permalink; if ( ! is_admin() ) { $permalink = $permalink . '#new_tab'; } } return $permalink; } /** * Redirect page/post to external permalink if it's loaded directly from the WP default permalink * * @since 3.9.0 */ public function redirect_to_external_permalink() { global $post; // If not on/loading the single page/post URL, do nothing if ( ! is_singular() ) { return; } $external_permalink = get_post_meta( $post->ID, '_links_to', true ); if ( ! empty( $external_permalink ) ) { wp_redirect( $external_permalink, 302 ); // temporary redirect exit; } } }