Single Post Pages for Custom Post Types

I have been developing a one page WordPress personal portfolio theme for Themeforest submission.

I have some sections in the front page which is my main page for this one page theme. The sections are:

  1. Service Section

  2. Portfolio Section

  3. Testimonial Section

  4. Team Section etc. etc.

And most of them are populated by custom post type.

Now my queries are:

  1. Is it mandatory to create single post page for each of the custom post types?

  2. If not, then what about the ‘href’ attribute value(where we write this code the_permalink()) of the anchor tag ()? Should I keep it dead like href=”#”?

  3. Is it mandatory to design Section Page, Portfolio Page etc. which are created by custom page templates?

  4. Is it mandatory to keep ‘has_archive’ => true in the custom post register?

N. B. This is a onepage personal portfolio WordPress theme.

Thanks in advance.

1 Answer
1

Is it mandatory to create single post page for each of the custom post types?
No not all all. If you add ‘publicly_queryable’ => false; the system won’t create single page entries for your cpts. (make sure to flush permalinks after this change)

If not, then what about the ‘href’ attribute value(where we write this code the_permalink()) of the anchor tag ()? Should I keep it dead like href=”#”?
with the publicly_queryable arg set to false, this will just load to the homepage

Is it mandatory to design Section Page, Portfolio Page etc. which are created by custom page templates? no its not. in fact if you set ‘has_archive’ => false; those pages won’t load either and if someone were to try to go to those archive pages “www.example.com/your_cpt” it will also load to the home page. (remember to flush permalinks after you make this change)

Is it mandatory to keep ‘has_archive’ => true in the custom post register? no. see the above questions answer.

To flush your permalinks. go to your dashboard and then settings/permalinks and hit save.

Alternately, you can add this into your plugin. This call should only be done as part of initialization though because it does use a lot of resources. This is how you would do it:

function my_rewrite_flush() {
    // First, we "add" the custom post type via the above written function.
    // Note: "add" is written with quotes, as CPTs don't get added to the DB,
    // They are only referenced in the post_type column with a post entry, 
    // when you add a post of this CPT.
    my_cpt_init();

    // ATTENTION: This is *only* done during plugin activation hook in this example!
    // You should *NEVER EVER* do this on every page load!!
    flush_rewrite_rules();
}

register_activation_hook( __FILE__, 'my_rewrite_flush' );

Much more information here too:
https://codex.wordpress.org/Function_Reference/register_post_type

Leave a Comment