Question

I'm trying to modify Wordpress "press this" http://codex.wordpress.org/Press_This to post with the post type that my theme created.

By default Post this open the link http://www.xxxx.com/wp-admin/post-new.php

And I want it to open http://www.xxxx.com/wp-admin/post-new.php?post_type=recipe

Have tried the following code in Functions.php but nothing happens

function press_this_ptype($link) {
    $post_type = 'recipe';

    $link = str_replace('post-new.php', "post-new.php?post_type=$post_type", $link);

    return $link;
}
add_filter('shortcut_link', 'press_this_ptype', 11);
Was it helpful?

Solution

Studying the file, I think the best entry point is the function wp_update_post() that has a filter we can use:

add_action( 'load-press-this.php', function() # Add filter only in Press This 
{
    add_filter( 'wp_insert_post_data', function( $data, $postarr ) 
    {
        $data['post_type'] = 'portfolio'; # <-- adjust CPT
        return $data;
    }, 10, 2 );
});

After that, we'll notice the need to hide some stuff from the Press This screen (post formats, categories, tags):

add_action( 'admin_head-press-this.php', function() 
{
    ?>
    <style type='text/css'>
    #categorydiv, #tagsdiv-post_tag,       /* Category and tag meta boxes */
    #submitdiv div.inside p:nth-of-type(2) /* Post formats */
    {
        display:none;
    }
    </style>
    <?php
});
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top