I've created a custom post type and on the admin page for that post type I want an image displayed that can act as a guide for the users uploading images. Is there a function that I can use to insert an image into the admin for just that custom post type. (I have tried to Google this but all the results seem to be related to uploading images).
3 Answers
You could add a custom help
Simple example taken from here
function mqw_example_contextual_help( $contextual_help, $screen_id) {
# Uncomment this to see actual screen
# echo 'Screen ID = '.$screen_id.'<br />';
switch( $screen_id ) {
case 'mycustompostname' : //Your custom post name
//Just to modify text of first tab
$contextual_help .= '<p>';
$contextual_help = __( 'Your text here and the image after.' );
$contextual_help .= '</p>';
break;
}
return $contextual_help;
}
add_filter('contextual_help', 'mqw_example_contextual_help', 10, 2);
-
-
Several options, but this seems most suitable for what I was looking for.– tommyfApr 15, 2013 at 11:24
You might also look into using the edit_form_after_title
action introduced in 3.5 Here's the introduction post for that and edit_form_after_editor
.
I think you'd need to think through the UI quite well and make the image hide-able (so this may not be the best way to handle it, but I do think those are appropriate hooks for contextual help at times (though add_help_tab
has its place like @t-f says).
Do you know the concept of WP Pointers?
Here's a short example introducing a pointer on the dashboard.
PHP
Put this either in your functions.php
if you define your CPT in your theme, or put it into your plugin if you define your CPT there:
add_action('admin_enqueue_scripts', 'my_pointer_load', 1000);
function my_pointer_load($hook_suffix) {
// Don't run on WP < 3.3
if (get_bloginfo('version') < '3.3') return;
$screen = get_current_screen();
$screen_id = $screen->id;
$pointers = apply_filters('my_admin_pointers-'.$screen_id, array());
if (! $pointers || ! is_array($pointers)) return;
// Get dismissed pointers
$dismissed = explode(',', (string) get_user_meta(get_current_user_id(),
'dismissed_wp_pointers', true));
$valid_pointers = array();
// Check pointers and remove dismissed ones.
foreach ($pointers as $pointer_id => $pointer) {
// Sanity check
if (in_array($pointer_id, $dismissed)
|| empty($pointer)
|| empty($pointer_id)
|| empty($pointer['target'])
|| empty($pointer['options'])
)
continue;
$pointer['pointer_id'] = $pointer_id;
// Add the pointer to $valid_pointers array
$valid_pointers['pointers'][] = $pointer;
}
// No valid pointers? Stop here.
if (empty($valid_pointers)) return;
wp_enqueue_style('wp-pointer');
wp_enqueue_script(
'my-wp-pointer',
// For a plugin use plugins_url('js/my-wp-pointer.js', __FILE__)
get_stylesheet_directory_uri().'/js/my-wp-pointer.js',
array('wp-pointer')
);
wp_localize_script('my-wp-pointer', 'myWPPointer', $valid_pointers);
}
// Let's add a pointer to the dashboard
add_filter('my_admin_pointers-dashboard', 'my_register_pointer');
function my_register_pointer($p) {
$p['some_pointer_id'] = array(
// What element do you want to explain?
// Use class (e.g., '.wrap') or ID (e.g., '#dashboard_right_now')
'target' => '.wrap',
'options' => array(
'content' => "<h3>Title</h3><p>What is it that you'd like to tell?</p>",
'position' => array(
'edge' => 'top',
'align' => 'middle',
)
)
);
return $p;
}
If you want a somewhat annoying and sticky pointer, remove the dismissed code from the above my_pointer_load
function.
JavaScript
Put the following in your /js/my-wp-pointer.js
file (or somewhere else and adjust the above wp_enqueue_script
):
jQuery(document).ready(function($) {
my_open_pointer(0);
function my_open_pointer(i) {
pointer = myWPPointer.pointers[i];
options = $.extend(pointer.options, {
close: function() {
$.post(ajaxurl, {
pointer: pointer.pointer_id,
action: 'dismiss-wp-pointer'
});
}
});
$(pointer.target).pointer(options).pointer('open');
}
});
Note: This answer is based on this tutorial.