Skip to content

Instantly share code, notes, and snippets.

@SitesByYogi
Last active December 27, 2024 11:54
Show Gist options
  • Save SitesByYogi/bc1d2a53c4b83583cd8f2dfce1e0d6ae to your computer and use it in GitHub Desktop.
Save SitesByYogi/bc1d2a53c4b83583cd8f2dfce1e0d6ae to your computer and use it in GitHub Desktop.
Creates shoppable template cpt
<?php
// Register Custom Post Type: Shoppable Articles
function create_shoppable_articles_post_type() {
$labels = array(
'name' => _x('Shoppable Articles', 'Post Type General Name', 'your-text-domain'),
'singular_name' => _x('Shoppable Article', 'Post Type Singular Name', 'your-text-domain'),
'menu_name' => __('Shoppable Articles', 'your-text-domain'),
'name_admin_bar' => __('Shoppable Article', 'your-text-domain'),
'archives' => __('Shoppable Article Archives', 'your-text-domain'),
'attributes' => __('Shoppable Article Attributes', 'your-text-domain'),
'parent_item_colon' => __('Parent Shoppable Article:', 'your-text-domain'),
'all_items' => __('All Shoppable Articles', 'your-text-domain'),
'add_new_item' => __('Add New Shoppable Article', 'your-text-domain'),
'add_new' => __('Add New', 'your-text-domain'),
'new_item' => __('New Shoppable Article', 'your-text-domain'),
'edit_item' => __('Edit Shoppable Article', 'your-text-domain'),
'update_item' => __('Update Shoppable Article', 'your-text-domain'),
'view_item' => __('View Shoppable Article', 'your-text-domain'),
'view_items' => __('View Shoppable Articles', 'your-text-domain'),
'search_items' => __('Search Shoppable Article', 'your-text-domain'),
'not_found' => __('Not found', 'your-text-domain'),
'not_found_in_trash' => __('Not found in Trash', 'your-text-domain'),
'featured_image' => __('Featured Image', 'your-text-domain'),
'set_featured_image' => __('Set featured image', 'your-text-domain'),
'remove_featured_image' => __('Remove featured image', 'your-text-domain'),
'use_featured_image' => __('Use as featured image', 'your-text-domain'),
'insert_into_item' => __('Insert into shoppable article', 'your-text-domain'),
'uploaded_to_this_item' => __('Uploaded to this shoppable article', 'your-text-domain'),
'items_list' => __('Shoppable articles list', 'your-text-domain'),
'items_list_navigation' => __('Shoppable articles list navigation', 'your-text-domain'),
'filter_items_list' => __('Filter shoppable articles list', 'your-text-domain'),
);
$args = array(
'label' => __('Shoppable Article', 'your-text-domain'),
'description' => __('Custom post type for shoppable articles', 'your-text-domain'),
'labels' => $labels,
'supports' => array('title', 'editor', 'excerpt', 'author', 'thumbnail', 'comments', 'trackbacks', 'revisions', 'custom-fields', 'post-formats'),
'taxonomies' => array('category', 'post_tag'),
'hierarchical' => false,
'public' => true,
'show_ui' => true,
'show_in_menu' => true,
'menu_position' => 5,
'menu_icon' => 'dashicons-cart', // Change icon if needed
'show_in_admin_bar' => true,
'show_in_nav_menus' => true,
'can_export' => true,
'has_archive' => true,
'exclude_from_search' => false,
'publicly_queryable' => true,
'capability_type' => 'post',
'show_in_rest' => true, // Enables Gutenberg support
);
register_post_type('shoppable_article', $args);
}
add_action('init', 'create_shoppable_articles_post_type', 0);
// Remove the title on Shoppable Articles pages
function remove_shoppable_articles_title($title, $id = null) {
// Check if it's a Shoppable Articles archive or single post
if ((is_post_type_archive('shoppable_article') || is_singular('shoppable_article')) && in_the_loop()) {
return ''; // Return an empty string to remove the title
}
return $title;
}
add_filter('the_title', 'remove_shoppable_articles_title', 10, 2);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment