Skip to content

Instantly share code, notes, and snippets.

@isotrope
Last active August 29, 2015 14:16
Show Gist options
  • Save isotrope/b389d287b83835600ba8 to your computer and use it in GitHub Desktop.
Save isotrope/b389d287b83835600ba8 to your computer and use it in GitHub Desktop.
Add an extra column for a specific Custom Post Type. Echo a shortcode, ready to copy-paste by the user.
<?php
/**
* Adds a shortcode column for a CPT
*
* In this example, my CPT's slug is ISO_SLIDER
*
* Uses
* http://codex.wordpress.org/Plugin_API/Filter_Reference/manage_$post_type_posts_columns
* http://codex.wordpress.org/Plugin_API/Action_Reference/manage_$post_type_posts_custom_column
*
*/
/**
* This is the "Tell WordPress to add an extra column when displaying the ISO_SLIDER CPT
*/
add_filter( 'manage_ISO_SLIDER_posts_columns', 'set_custom_edit_iso_slider_columns' );
function set_custom_edit_iso_slider_columns( $columns ) {
/**
* Add a column with a slug of 'iso_slider_shortcode'
*/
$columns['iso_slider_shortcode'] = __( 'Shortcode', 'your-textdomain' );
return $columns;
}
/**
* This is the "Display what I want in the column" bit
*/
add_action( 'manage_ISO_SLIDER_posts_custom_column', 'iso_display_slider_columns', 10, 2 );
function iso_display_slider_columns( $column, $post_id ) {
switch ( $column ) {
/*
* If we're currently looking at the 'iso_slider_shortcode', echo 'stuff'
*/
case 'iso_slider_shortcode' :
if ( ! empty( $url ) ) {
echo '<input type="text" class="shortcode-in-list-table wp-ui-text-highlight code" value=\'[slider_shortcode id="' . $post_id . '"]\' readonly="readonly" onfocus="this.select();" size="50">';
}
break;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment