Support » Plugin: Press This » Press This: Default category?

  • I have a non tech-savvy user that uses Press This. She can remember to hit “Scan” to pull images, but she can’t consistently remember to select a category (“News”).

    Is there a way of just having all Press This created posts default to a specific category?

Viewing 5 replies - 1 through 5 (of 5 total)
  • Hi there,
    I’m also using the Press This bookmarklet and am looking to do the following:

    1. Create a default post format (“Link” post format) for posts coming from Press This
    2. Create a default category (i.e. “link”) for posts coming from Press This

    Is this possible? If so, how best to accomplish that?

    • This reply was modified 3 months, 2 weeks ago by bradfrost.

    Setting a default category or post format for posts saved via PressThis can be achieved via filter press_this_save_post.

    (For guidance on using filters see the docs in the Plugin Handbook.)

    Untested example (using PHP 5.6+ syntax):

    /**
     * Add category and post format to PressThis post before saving
     */
    add_filter( 'press_this_save_post', function ( $post_data ) {
    
    	// See https://github.com/WordPress/press-this/blob/master/class-wp-press-this-plugin.php#L117
    	$post_data[ 'post_format' ] = 'link';
    
    	// Not sure, I _think_ this expects an array, but I could be wrong.
    	// See https://github.com/WordPress/press-this/blob/master/class-wp-press-this-plugin.php#L123
    	$post_data['post_category'] = [ 'some-category' ];
    
    	return $post_data;
    } );
    

    This function could be wrapped in a PHP file and stored as a little plugin, or MU plugin.

    Ok, turns out setting the category didn’t work that way, you’ll need to get its ID from its slug first.

    I’ve refined the code so that it works and wrapped it into a little plugin. So you can download the Gist, upload to /wp-content/plugins, and activate as usual:
    https://gist.github.com/glueckpress/fc0ef2d8f9a245163f1162f4f13ab1ca

    Well hey! Casper, you’re the man! I plugged in your gist and now publishing a post from Press This defaults to the link category and post type. Thanks so incredibly much for sharing this! I now feel empowered to share way more on my blog than I was before. Thanks a million.

    My pleasure, @brad_frost! 🙌

Viewing 5 replies - 1 through 5 (of 5 total)
  • You must be logged in to reply to this topic.