Converting hashtags in posts to WordPress Tags. This code works only for web WP Admin posts; can it be modified to work for Jetpack official mobile app posts?

[ad_1]

**Desired outcome:**
Converting hashtags within post content to WordPress tags using mobile apps (and not just web admin posts)?

The following code ([sourced from stack overflow](https://stackoverflow.com/questions/58362466/add-a-wordpress-taxonomy-tag-for-hashtags-in-wordpress-content)) works when posting from web WP Admin Backend, can it be modified to also work when posting from official mobile apps such as ‘Jetpack App’ and ‘WordPress App’?

function post_published_notification( $ID, $post ) {
$content = $post->post_content;
preg_match_all(‘/( #\w+)/’, $content, $matches, PREG_PATTERN_ORDER);
if(isset($matches[1])){
foreach($matches[1] as $matchKey){
wp_set_post_tags( $ID, trim($matchKey), true);
}
}
}
add_action( ‘publish_post’, ‘post_published_notification’, 10, 2 );

What are your thoughts? Possible?

[ad_2]
2 Comments
  1. I’ve never used Jetpack, so I’m not sure how posts are being handled using it. A quick search gave me the following article, but I’m not sure if it’s helpful for you: [Jetpack Content Options](https://jetpack.com/support/content-options/). If it’s not the case yet, it could be that you have to enable theme support.

    My other guess is that a custom post type is being used that doesn’t respond to the specific function. If you’re able to provide us with a link of a post you’ve created using Jetpack, I can checkout the source code to see the post type.

  2. You’ll want to have that same action fire when a post is created through the REST API, that’s what the apps use.

    Add this below the existing action, it should work for what you want:

    add_action( ‘rest_after_insert_post’, ‘post_published_notification’, 10, 2 );

 

This site will teach you how to build a WordPress website for beginners. We will cover everything from installing WordPress to adding pages, posts, and images to your site. You will learn how to customize your site with themes and plugins, as well as how to market your site online.

Buy WordPress Transfer