Check IF is a “single product page” and Check the “role” for a Redirect

Here is the result that works, I put in the condition : is_product() to check if is a single product page. And I changed in the add_action() : admin_init by wp function cm_redirect_users_by_role() { $current_user = wp_get_current_user(); $role_name = $current_user->roles[0]; if ( is_product() ){ if ( $role_name !== ‘customer’ && $role_name !== ‘shop_manager’ && $role_name … Read more

What is singular.php?

It’s the nature of the WordPress template hierarchy – point being, if you don’t have a page.php, it will use singular.php, same if you don’t have single.php, it will fallback to a template lower in the hierarchy. Ideal for themes that have the same layout for posts/pages, instead of having duplicate code in each respective … Read more

Custom post type single page returns 404 error

You should set your publicly_queryable argument to true when registering your custom post type. TAKE NOTE: Add flush_rewrite_rules(), refresh the page once or twice and REMOVE IT IMMEDIATELY. You SHOULD NOT keep flush_rewrite_rules() unless under the provisions as in the codex. this is an expensive operation so it should only be used when absolutely necessary

How to disable the single view for a custom post type?

METHOD 1: Redirect to a custom URL for single view, archive page is still publicly accessible. You can use template_redirect hook to redirect for a custom post type, you can use any other URL you want to in place of home_url() and the error code in other argument. <?php add_action( ‘template_redirect’, ‘wpse_128636_redirect_post’ ); function wpse_128636_redirect_post() … Read more