Snippets
Created by
Joseph Dickson
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 | <?php
/**
* Plugin Name: Hero Image and Featured Content Tiles
* Description: Custom Post Type for Hero Images and featured content tiles that can be used on a homepage or front page. Requires customizations to the active theme.
* Author: Joseph Dickson
* Author URI: https://joseph-dickson.com
* Version: 0.1
* License: GPL2
*/
// Prevent direct access to this file
defined( 'ABSPATH' ) or die( 'No script kiddies please!' );
/**
*
* https://codex.wordpress.org/Function_Reference/register_post_type#Arguments
*/
function pz_rrc_custom_post_types() {
/**
* Hero Images for the Front Page
* Theme will need to be configured using WP Query
*/
$labels = array(
'name' => 'Front Page',
'singular_name' => 'Front Page',
'menu_name' => 'Front Page',
'name_admin_bar' => 'Hero Image',
'add_new' => 'Add a Hero Image',
'add_new_item' => 'Hero Image',
'new_item' => 'Hero Image',
'edit_item' => 'Edit Hero Image',
'view_item' => 'View Hero Image',
'all_items' => 'All Hero Images',
'search_items' => 'Search Hero Images',
'parent_item_colon' => 'Parent Hero Images:',
'not_found' => 'No Hero Images found.',
'not_found_in_trash' => 'No Hero Images found in Trash.',
);
$args = array(
'labels' => $labels,
'public' => true,
'publicly_queryable' => false,
'show_ui' => true,
'show_in_menu' => true,
'menu_icon' => 'dashicons-format-image',
'query_var' => true,
'rewrite' => array( 'slug' => 'hero-image' ),
'capability_type' => 'post',
'has_archive' => false,
'hierarchical' => false,
'menu_position' => 5,
'show_in_rest' => true,
'supports' => array( 'title', 'editor', 'thumbnail' ),
);
register_post_type( 'hero-image', $args );
/**
* Featured Content Tiles for the Front Page
* Theme will need to be configured using WP Query
*/
$labels = array(
'name' => 'Featured Content',
'singular_name' => 'Featured Content',
'menu_name' => 'Featured Content',
'name_admin_bar' => 'Tile',
'add_new' => 'Add a Tile',
'add_new_item' => 'Add a Tile',
'new_item' => 'New Tile',
'edit_item' => 'Edit Featured Content',
'view_item' => 'View Featured Content Tiles',
'all_items' => 'Tiles',
'search_items' => 'Search Featured Content Tiles',
'parent_item_colon' => 'Parent Featured Content Tiles:',
'not_found' => 'No Featured Content Tiles found.',
'not_found_in_trash' => 'No Featured Content Tiles found in Trash.',
);
$args = array(
'labels' => $labels,
'public' => true,
'publicly_queryable' => false,
'show_ui' => 'edit.php?post_type=hero-image',
'show_in_menu' => 'edit.php?post_type=hero-image',
'menu_icon' => 'dashicons-format-image',
'query_var' => true,
'rewrite' => array( 'slug' => 'featured-content' ),
'capability_type' => 'post',
'has_archive' => false,
'hierarchical' => false,
'menu_position' => 5,
'show_in_rest' => true,
'supports' => array( 'title', 'editor', 'thumbnail' ),
);
register_post_type( 'featured-content', $args );
}
add_action( 'init', 'pz_rrc_custom_post_types' );
if ( function_exists( 'add_theme_support' ) ) {
add_image_size( 'event-thumb', 370, 208, array( 'center', 'center' ) ); // Custom thumbnail size for the events on the front page
add_image_size( 'featured-content', 690, 350, array( 'center', 'center' ) ); // Custom thumbnail size for the featured content on the front page
}
// Flush rewrite rules to add "Zest" as a permalink slug when plugin is activated
function my_rewrite_flush() {
pz_rrc_custom_post_types();
flush_rewrite_rules();
}
register_activation_hook( __FILE__, 'my_rewrite_flush' );
|
Comments (0)
You can clone a snippet to your computer for local editing. Learn more.