Problem with shortcodes in external file

enter image description here

I have simple post with a shortcode:

[xx]http://harrix.org/1.txt[xx]

And an external file which has the content containing a WordPress shortcode:

[strong] g[/strong]

I try add my own tag to load the external file:

<?
add_filter('the_content', 'WorkWithTags');
function WorkWithTags($content){
$Tag ="xx";

if (preg_match_all('~['.$Tag.'](.*?)[/'.$Tag.']~is', $content, $arr)) 
{ 
   foreach ($arr[1] as $value) 
   {
      $newvalue = @file_get_contents($value);//Main String

      $content=str_replace($value, $newvalue, $content);
   }

   //Delete tags
   $tr=array('['.$Tag.']'=>'','[/'.$Tag.']'=>'',); 
   $content=strtr($content,$tr);
}
return $content;
}
?>

Adding file works good. But the external file contains shortcodes of WordPress. How can I get WordPress to execute all of the shortcodes from this external file?

Update.

I try use code by s_ha_dum in functions.php:

function WorkWithTags($atts,$content){
  $atts = shortcode_atts(
    array(
      'tag' => 'xx'
    ),
    $atts
  );
  $fo = $atts['tag'];
  $content = file_get_contents($fo);//Main String
  return do_shortcode($content);
}
add_shortcode('wwt','WorkWithTags');

Then I add this shortcode in post:

Text. Text. Text. Text. Text. Text. Text. Text. 

[wwt tag="http://harrix.org/1.txt" /]

Text. Text. Text. Text. Text. Text. Text. Text.

enter image description here

And I see that in preview of post:

enter image description here

I can not run shortcodes in an external file.

Read more here:: Problem with shortcodes in external file

Leave a Reply

Your email address will not be published. Required fields are marked *