emreyildz41 adlı üyeden alıntı: mesajı görüntüle
Bu kodu eklediğimde rest-api sayfasında hata alıyordum. bende başka bi yerde bu kodu buldum. bu kodla açıklamayı nasıl tek cümleye düşürebilirm

function custom_product_description($atts){    global $product;     try {        if( is_a($product, 'WC_Product') ) {            return wc_format_content( $product->get_description("shortcode") );        }         return "Product description shortcode run outside of product context";    } catch (Exception $e) {        return "Product description shortcode encountered an exception"; } }
add_shortcode( 'custom_product_description', 'custom_product_description' );
function custom_product_description($atts){
    global $product;

    try {
        if( is_a($product, 'WC_Product') ) {
            // Ürün açıklamasını "shortcode" formatında alıyoruz.
            $description = $product->get_description("shortcode");
            
            // Öncelikle isterseniz HTML etiketlerini temizleyebilirsiniz
            // (HTML etiketleri gerekmediği durumlarda faydalı olabilir).
            $description = wp_strip_all_tags($description);

            // Nokta, soru veya ünlem işaretinden sonra gelen boşluğa göre parçalama yapıyoruz.
            // preg_split ile 2 parçaya ayırıyoruz, böylece ilk cümleyi ve geri kalanı elde ediyoruz.
            $sentences = preg_split('/([.?!])\s/', $description, 2, PREG_SPLIT_DELIM_CAPTURE);

            // $sentences[0] ilk cümlenin metin kısmını,
            // $sentences[1] ise cümlenin sonundaki noktalama işaretini tutar (eğer varsa).
            $firstSentence = $sentences[0];

            // Cümle sonu noktalamasını da eklemek isterseniz:
            if(isset($sentences[1])) {
                $firstSentence .= $sentences[1];
            }

            // İlk cümleyi döndürüyoruz
            return $firstSentence;
        }

        return "Product description shortcode run outside of product context";
    } catch (Exception $e) {
        return "Product description shortcode encountered an exception";
    }
}
add_shortcode( 'custom_product_description', 'custom_product_description' );