0

I'm trying to add a filter to the add media button for a custom post type. I'm using add_filter('media_send_to_editor') and it work's fine, but I'm having difficulty finding a way to determine the post type of the admin page so that I can only perform the filter on that specific post type. Any ideas on how I can get the post post type?

I'm trying to filter the output of the image and caption, but I only want to do it on a specific post type. I would need the other post types to function as normally when adding images. I need the the image to be wrapped in a shortcode and the caption to be included in a parameter for that shortcode. I have it working. I just need a way to make it conditional for post types.

  • what do you want to filter ? edit your question to add more details and a example. – mmm Apr 11 '18 at 19:14
0

to test the post type where the image is included, try that :

add_filter("media_send_to_editor", function ($html, $attachment_id, $attachment) {


    $image = get_post($attachment_id);
    $post = get_post($image->post_parent);

    if ("CUSTOM_POST_TYPE_CODE" === $post->post_type) {


    }


    return $html;

}, 10, 3);
0

PS : this doesn't answer the question but can help readers

you can conditionaly remove the button withe the filter wp_editor_settings

add_filter("wp_editor_settings", function ($settings, $editor_id) {

    $current_screen = get_current_screen();

    if ("CUSTOM_POST_TYPE" === $current_screen->post_type) {
        $settings["media_buttons"] = FALSE;
    }


    return $settings;

}, 10, 2);
  • Thanks for the answer. I actually want to continue to include the upload media button. I only want to filter it for the specific post type. – Shaned9 Apr 11 '18 at 18:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.