0

I have a script that checks status (daily with cron) of some sites and write result in a xml document. Xml is like this :

<?xml version="1.0" encoding="UTF-8"?>
 <xml>
  <sites>
   <site1>result of site1</site1>
   <site2>result of site2</site2>
   ...
  </sites>
 </xml>

Then i have a function that let me get xml content for each site with wordpress shortcodes , like this :

<?php
function CheckRemoteService($atts) {
 extract(shortcode_atts(array(
  'name' => 'txt',
 ), $atts));

$xml = simplexml_load_file('my.xml');
echo $xml->sites->$name;

}
add_shortcode('checkmyurl','CheckRemoteService');
?>

Shortcodes give me the correct output but all results are placed on same row at top , like if are blocked there. I want to insert these results in a table with other data. Is this a xml limit or i have done some mistakes ? Thanks.

1 Answer 1

0

Shortcodes must return content and not echo it. See any of the examples in the codex for add_shortcode()

So your callback function should probably be:

function CheckRemoteService($atts) {
 extract(shortcode_atts(array(
  'name' => 'txt',
 ), $atts));

$xml = simplexml_load_file('my.xml');
return $xml->sites->$name;

}
add_shortcode('checkmyurl','CheckRemoteService');
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.