NB: Make sure you do a back up of your theme, files and database before attempting the tutorials
Last modified : Oct 01 2022
Estimated reading time : 1 minute, 47 seconds - 183 words
Share the post "Hiding Post Type URL In Admin Pages"
With this tutorial, we’ll show you how to hide a Post Type’s URL so if you create a custom post type that doesn’t require the single, we might want to hide the URL from our customers.
Here’s the image.
And then if you to optimize these results so your Post Types aren’t displayed in Google SERPs; a slider or hidden data for example. Make sure to check your variables in your function are (Click here to learn how to create a custom post type):
public => false,
has_archive => false
publicly_queryable => false
In our WordPress function, which we will implement in our functions.php or plugin core file, we will add a condition to hide the link if the Post Type is in the Admin head such as:
///////////////////////////////////////////// //////// Permalinks display no ////////////// ///////////////////////////////////////////// add_action('admin_head', 'votretheme_permalink_none'); function votretheme_permalink_none() { global $post_type; if ($post_type == 'CPT_NAME_HERE' ) { echo '<style>#edit-slug-box, #message a {display:none;}</style>'; } elseif ($post_type == 'CPT_NAME_HERE' ) { echo '<style>#edit-slug-box, #message a, #post-status-info, #postdivrich {display:none;}</style>'; } }
You can also add a condition where all your Archive and Single post types are redirected to your homepage. That way Google won’t index those. If you don’t want to use this function, you can also do so via the highly recommended Yoast SEO plugin.
function votretheme_postype_redirect() { global $wp_query; // redirect from 'slideshow' CPT to home page if ( is_archive('CPT_NAME_HERE') || is_singular('CPT_NAME_HERE') ) : $url = get_bloginfo('url'); wp_redirect( esc_url_raw( $url ), 301 ); exit(); endif; } add_action ( 'template_redirect', votretheme_postype_redirect', 1);