Yes, but my problem is that I need to manually add this shorcode to all of syndicated articles, is there any way to do that in some automated way?
When I place this snippet inside all websites within network and syndicate article from one site to all other on network, I need manually insert shortcode to the bottom of every syndicated article.
Appreciated!
Hook into the the_content filter?
https://developer.wordpress.org/reference/hooks/the_content/
In that filter
1. decide whether the post needs the shortcode
2. do_action the broadcast shortcode
3. take the result of the do_action and put it in the content
Yes, but I stuck on point ONE – decide whether the post needs the shortcode. That part shoud be defined by condition that post is syndicated from other website and that is where I’m stuck at.
How to define that post is syndicated, thus that filter add shortcode to only that type of post?
With #1 I was thinking more in terms of “is this a page, post or a menu” and similar.
You can go ahead and skip it. If the post is not broadcasted, the do_shortcode won’t return anything.
I am sorry but now I am totally confused 🙂 Could you throw me just a simple code example here, because I am lost now…
First, add the shortcode code snippet from the above link.
Second, add this code snippet. It appends the shortcode to the post content.
add_filter( ‘the_content’, function( $content )
{
// Get the broadcasted from text.
$sc_text = do_shortcode( ‘[broadcasted_from]’ );
// Add the text to the content.
$content .= $sc_text;
// Return the expanded content.
return $content;
} );
Untested, but it should work.