Snippets

Joseph Dickson WordPress: "Now" Custom Post Type

Created by Joseph Dickson last modified
<?php
/**
 * Plugin Name: JD Now Posts 
 * Description: Custom Post Type for Now posts
 * Version: 1.0
 * License: GPL2
 */

// Prevent direct access to this file
defined( 'ABSPATH' ) or die( 'No script kiddies please!' );

/**
 * https://developer.wordpress.org/reference/functions/register_post_type/
 */
function jd_now_custom_post_type() {

	$labels = array(
		'name'			=> 'Now',
		'singular_name'		=> 'Now',
		'menu_name'		=> 'Now',
		'name_admin_bar'	=> 'Now',
		'add_new'		=> 'Add a Now post',
		'add_new_item'		=> 'Now',
		'new_item'		=> 'Now',
		'edit_item'		=> 'Edit Now post',
		'view_item'		=> 'View Now post',
		'all_items'		=> 'All Now posts',
		'search_items'		=> 'Search Now posts',
		'parent_item_colon'	=> 'Parent Now Posts:',
		'not_found'		=> 'No Now posts found.',
		'not_found_in_trash'	=> 'No Now posts found in Trash.',
	);

	$args = array(
		'labels'		=> $labels,
		'public'		=> true,
		'publicly_queryable'	=> true,
		'show_ui'		=> true,
		'show_in_menu'		=> true,
		'menu_icon'		=> 'dashicons-format-chat',
		'query_var'		=> true,
		'rewrite'		=> array( 'slug' => 'now' ),
		'capability_type'	=> 'post',
		'has_archive'		=> true,
		'hierarchical'		=> false,
		'menu_position'		=> 16,
		'show_in_rest'		=> true,
		'supports'		=> array( 'title', 'editor', 'thumbnail' ),
	);

	register_post_type( 'now', $args );

}

add_action( 'init', 'jd_now_custom_post_type' );

// Flush rewrite rules when plugin is activated
function jd_now_rewrite_flush() {
	jd_now_custom_post_type();
	flush_rewrite_rules();
}

register_activation_hook( __FILE__, 'jd_now_rewrite_flush' );

if ( function_exists( 'add_theme_support' ) ) {
	add_theme_support( 'post-thumbnails' );
}

Comments (1)

HTTPS SSH

You can clone a snippet to your computer for local editing. Learn more.