/* 
Theme Name: Hello Child
Theme URI: https://elementor-site.ir/
Description: 
Author: Elementor Site
Author URI: https://elementor-site.ir/
Template: hello-elementor
Version: 1.0.1
Text Domain: hello-elementor-child
License: GNU General Public License v3 or later.
License URI: https://www.gnu.org/licenses/gpl-3.0.html
Tags: flexible-header, custom-colors, custom-menu, custom-logo, editor-style, featured-images, rtl-language-support, threaded-comments, translation-ready
*/
/**
 * Optimize Featured Image for Better LCP
 * Usage: [featured_image_lcp]
 */
function lcp_featured_image_shortcode() {

    if ( is_singular() && has_post_thumbnail() ) {

        $thumb_id = get_post_thumbnail_id();
        $alt = get_post_meta( $thumb_id, '_wp_attachment_image_alt', true );
        $alt = $alt ? esc_attr( $alt ) : esc_attr( get_the_title() );

        $src_full = wp_get_attachment_image_url( $thumb_id, 'full' );
        $srcset   = wp_get_attachment_image_srcset( $thumb_id, 'full' );
        $sizes    = wp_get_attachment_image_sizes( $thumb_id, 'full' );

        return '<img 
            src="' . esc_url( $src_full ) . '" 
            loading="eager" 
            fetchpriority="high" 
            data-no-lazy="1"
            alt="' . $alt . '"
            srcset="' . esc_attr( $srcset ) . '"
            sizes="' . esc_attr( $sizes ) . '"
            style="width:100%;height:auto;"
            class="featured-lcp-img"
        >';
    }

    return '';
}
add_shortcode( 'featured_image_lcp', 'lcp_featured_image_shortcode' );
function my_custom_shortcode_function() {
    return '<p>این متن توسط شورت‌کد نمایش داده می‌شود.</p>';
}
add_shortcode('myshortcode', 'my_custom_shortcode_function');


// Shortcode ساده برای نمایش متن
function my_simple_shortcode() {
    return "Hello! This is my first shortcode 😊";
}

// ثبت Shortcode با نام [mytext]
add_shortcode('mytext', 'my_simple_shortcode');function my_param_shortcode($atts) {
    return "سلام، دوست من!";
}
add_shortcode('myparam', 'my_param_shortcode');
// تابع شورت‌کد
function my_simple_shortcode() {
    return "<p>سلام، دوست من! این متن توسط شورت‌کد نمایش داده می‌شود.</p>";
}// شورت‌کد نمایش تصویر
function my_image_shortcode() {
    // آدرس تصویرت رو اینجا قرار بده
    $image_url = "https://yourwebsite.com/wp-content/uploads/2025/11/example.jpg";

    return '<img src="' . esc_url($image_url) . '" alt="تصویر نمونه" style="max-width:100%;height:auto;">';
}

// ثبت شورت‌کد با نام [myimage]
add_shortcode('myimage', 'my_image_shortcode');

/**
 * Shortcode برای نمایش هر تصویر دلخواه
 * استفاده: [myimage src="آدرس_تصویر" alt="متن جایگزین"]
 */
function my_custom_image_shortcode($atts) {
    // پارامترها و مقدار پیش‌فرض
    $atts = shortcode_atts(array(
        'src' => '',    // لینک تصویر
        'alt' => '',    // متن جایگزین
        'width' => '100%', // عرض پیش‌فرض
        'height' => 'auto' // ارتفاع پیش‌فرض
    ), $atts, 'myimage');

    // اگر src خالی باشه، چیزی نمایش نمی‌ده
    if (empty($atts['src'])) {
        return '';
    }

    // ساخت تگ تصویر با ویژگی‌ها
    return '<img 
        src="' . esc_url($atts['src']) . '" 
        alt="' . esc_attr($atts['alt']) . '" 
        style="width:' . esc_attr($atts['width']) . ';height:' . esc_attr($atts['height']) . ';"
        loading="eager"
        fetchpriority="high"
    >';
}

// ثبت شورت‌کد با نام [myimage]
add_shortcode('myimage', 'my_custom_image_shortcode');
   
