• Resolved rakeshnirzari1

    (@rakeshnirzari1)


    Hi, I added php snippet using the plugin but when I put the short code to my page, it is giving me “There has been a critical error on this website.”

    Here is the php code

    <?php 
       // Web page URL 
    $url = 'https://www.shopback.com.au/althea-cashback'; 
     
    // Extract HTML using curl 
    $ch = curl_init(); 
    curl_setopt($ch, CURLOPT_HEADER, 0); 
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
    curl_setopt($ch, CURLOPT_URL, $url); 
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); 
     
    $data = curl_exec($ch); 
    curl_close($ch); 
     
    // Load HTML to DOM object 
    $dom = new DOMDocument(); 
    @$dom->loadHTML($data); 
     
    // Parse DOM to get Title data 
    $nodes = $dom->getElementsByTagName('title'); 
    $title = $nodes->item(0)->nodeValue; 
     
    // Parse DOM to get meta data 
    $metas = $dom->getElementsByTagName('meta'); 
     
    $description = $keywords = ''; 
    for($i=0; $i<$metas->length; $i++){ 
        $meta = $metas->item($i); 
         
        if($meta->getAttribute('name') == 'description'){ 
            $description = $meta->getAttribute('content'); 
        } 
         
        if($meta->getAttribute('name') == 'keywords'){ 
            $keywords = $meta->getAttribute('content'); 
        } 
    } 
     
    $myString = "$title";
       function getBetween($content,$start,$end){
        $r = explode($start, $content);
        if (isset($r[1])){
            $r = explode($end, $r[1]);
            return $r[0];
        }
        return '';
      }
     $content = "$title";
      $start = "2021 | ";
      $end = " Cashback";
      $output = getBetween($content,$start,$end);
      echo $output;
    ?>
Viewing 5 replies - 1 through 5 (of 5 total)
  • Thread Starter rakeshnirzari1

    (@rakeshnirzari1)

    When I put the php file on my website and open the URL, I am getting the result “4.50%” however when I use your plugin and put shortcode on the wordpress post, I am getting the error. Please help. e.g.

    Plugin Support Temyk

    (@webtemyk)

    Hello.

    I added your code to my snippet and it worked. There were no mistakes. Check that you don’t have any errors in the snippet code editor (underlined in red)

    Thread Starter rakeshnirzari1

    (@rakeshnirzari1)

    Thank you Artem. Appreciated. I checked the code editor and there are no errors (with red underline). I still get the error on the page where I am posting this shortcode. See an image below

    Thread Starter rakeshnirzari1

    (@rakeshnirzari1)

    I logged the error and here it is

    Thread Starter rakeshnirzari1

    (@rakeshnirzari1)

    Its resolved now. I am so silly that I put function code in the php snippet. I moved the function code to function.php and its fixed.

    `function getBetween($content,$start,$end){
    $r = explode($start, $content);
    if (isset($r[1])){
    $r = explode($end, $r[1]);
    return $r[0];
    }
    return ”;
    }

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘There has been a critical error on this website.’ is closed to new replies.