Use case: There are YouTube links on my WordPress posts. I want to automatically get the youtube video to appear on the respective discourse post after publishing the WordPress post.
Problem: It doesn’t seem to work because after syncing, the discourse post html is
the youtube video will only successfully appear if i remove the <p></p>
so how do i remove the <p></p>? I hope not to remove the <p></p> tags manually as I might have thousands of posts.
Not sure if I can remove the <p></p> tags directly in the functions.php file.
I followed your customization tutorial. This is the code in the functions.php
// Adds the featured image to the post that is published to Discourse.
function my_namespace_publish_format( $input ) {
ob_start();
?>
{excerpt} **<-----can i remove the p tags here?**
<?php
$output = ob_get_clean();
// Note: the call to apply_filters() that was in the original function has been removed.
return $output;
}
add_filter( 'discourse_publish_format_html', 'my_namespace_publish_format' );
This should work if the videos are embedded on your WordPress site. It make take some trial and error to get the formatting correct. The main problem I ran into with it was that if there are leading spaces before the Youtube iframe tag, Discourse will interpret it as code.
Let me know if this approach doesn’t work on your site.
What I would like to get to work would be to have Youtube videos displayed when users click the “Show Full Post” button on Discourse to expand a WordPress post. I am not sure if that is going to be possible though.
The output from your first code example looks close to what I was expecting. I think the problem with it is that you need to add https://www.youtube.com/embed to your Discourse allowed iframes site setting. That will allow the iframe that is in the post’s markup to display as a video player on Discourse.
Can you try publishing a post without using the custom template now? It may be that all that needed to be done was to add https://www.youtube.com/embed to your Discourse allowed iframes site setting.
Which editor are you using on your WordPress site, the old Classic Editor, or the new Block Editor? Also, are you publishing the full post to Discourse, or just an excerpt?
This could be done by writing a small script to publish posts from a CSV file.
To prevent the link to your WordPress domain appearing below the topic title, deselect the “Add Featured Links” option on your WP Discourse Publishing settings page. To remove the featured link from posts that have already been published, the link can either be hidden with CSS, or it can be removed from your Discourse site’s database. I am away from work for the next couple of days, but can take care of that for you when I get back to work on Wednesday.
If you can wait until Wednesday, I can give you a hand with this. If you need to do it sooner than that, you could try creating a new topic in our support category that asks how to create topics through the API from a CSV file.