Skip to content

Instantly share code, notes, and snippets.

@dhaval-parekh
Created March 31, 2022 08:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dhaval-parekh/7c9f3d68d6e37e66314206ad0aceb15a to your computer and use it in GitHub Desktop.
Save dhaval-parekh/7c9f3d68d6e37e66314206ad0aceb15a to your computer and use it in GitHub Desktop.
AMP eligible post type test.
<?php
/**
* Plugin Name: AMP eligible post type test.
* Description: Plugin to test eligible post types for AMP
* Version: 0.1
*
* @wordpress-plugin
* @author Dhaval Parekh
*/
add_action( 'init', function () {
register_post_type(
'book',
[
'label' => 'Book',
'publicly_queryable' => true,
]
);
register_post_type(
'car',
[
'label' => 'Car',
'public' => false,
'publicly_queryable' => true,
]
);
register_post_type(
'secret',
[
'label' => 'Secret',
'publicly_queryable' => false,
]
);
register_post_type(
'secret_book',
[
'label' => 'Secret book',
'public' => true,
'publicly_queryable' => false,
]
);
register_post_type(
'secret_car',
[
'label' => 'Secret Car',
'public' => false,
'publicly_queryable' => true,
]
);
} );
add_filter( 'is_post_type_viewable', function ( $is_viewable, $post_type ) {
if ( 'secret_car' === $post_type->name ) {
return false;
}
return $is_viewable;
}, 10, 2 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment