رایگان • فارسی • راست‌چین

دکمه شناور شبکه‌های اجتماعی برای وردپرس

یک دکمه شناور شیک با منوی بازشونده برای روبیکا، تلگرام، واتساپ، تماس و … همراه با پنل مدیریت فارسی. بدون نیاز به افزونه سنگین؛ فقط با افزونه Code Snippets فعالش کنید.


آموزش نصب

پیش‌نمایش (کلیک کنید)

  • روبیکا
  • تلگرام
  • واتساپ
  • تماس

دانلود

یکی از دو روش را انتخاب کنید؛ روش اول ساده‌تر است.

پیشنهادی

فایل نصب آماده (JSON)

مستقیم داخل افزونه Code Snippets وارد می‌شود و نیازی به کپی و پیست نیست.

دستی

کد PHP

کد را کپی کنید یا به‌صورت فایل متنی دانلود کنید و داخل یک قطعه‌کد جدید بچسبانید.

آموزش نصب و فعال‌سازی

در کمتر از ۳ دقیقه دکمه روی سایت شما فعال می‌شود.

  1. نصب افزونه Code Snippetsدر پیشخوان وردپرس به افزونه‌ها ← افزودن بروید، عبارت Code Snippets را جستجو کنید، نصب و سپس فعال کنید. صفحه افزونه در وردپرس
  2. روش اول: وارد کردن فایل (ساده‌ترین)از منوی قطعه کدها (Snippets) ← درون‌ریزی (Import) فایل JSON دانلودشده را انتخاب و روی Import بزنید.
  3. روش دوم: افزودن دستیاز قطعه کدها ← افزودن (Add New) بروید، یک عنوان مثل «دکمه شناور» بنویسید، نوع را PHP بگذارید و کد را در کادر بچسبانید. عبارت <?php را اول کد نگذارید.
  4. گزینه اجرا را روی «همه‌جا» بگذاریدزیر کادر کد، حالت اجرا باید Run snippet everywhere (اجرا در همه‌جا) باشد؛ چون هم دکمه در سایت و هم پنل در پیشخوان کار می‌کند.
  5. ذخیره و فعال‌سازیروی Save Changes and Activate بزنید. اگر فایل را Import کرده‌اید، در لیست قطعه‌کدها کلید روشن/خاموش را فعال کنید.
  6. تنظیم لینک‌ها و رنگ‌هایک منوی جدید به نام دکمه شناور در پیشخوان اضافه می‌شود. شماره‌ها، لینک‌ها، آیکون‌ها، رنگ و فاصله دکمه را از همان‌جا تغییر دهید و ذخیره کنید.
نکته مهم: شماره‌ها و لینک‌های پیش‌فرض داخل کد نمونه هستند. حتماً بعد از فعال‌سازی، آن‌ها را از پنل «دکمه شناور» به شماره و آی‌دی خودتان تغییر دهید.
اگر مشکلی پیش آمد:

  • یک قطعه‌کد را دو بار اضافه نکنید؛ در غیر این صورت خطای تکراری بودن تابع می‌دهد.
  • دکمه دیده نمی‌شود؟ کش سایت (و افزونه‌های کش) را پاک کنید.
  • پنل دکمه شناور نیست؟ حالت اجرا را روی «اجرا در همه‌جا» بگذارید.

مشاهده کد

در صورت نیاز می‌توانید کد کامل را قبل از نصب بررسی کنید.

نمایش کد کامل PHP
if ( ! defined( 'ABSPATH' ) ) exit;

/* ============================================================
   1) داده‌های پیش‌فرض
   ============================================================ */
function wafm_default_items() {
    return array(
        array(
            'label' => 'روبیکا',
            'icon'  => 'rubika',
            'url'   => 'https://rubika.ir/09126803497',
            'color' => '#F2461B',
   
        ),
        array(
            'label' => 'تلگرام',
            'icon'  => 'telegram',
            'url'   => 'https://t.me/09126803497',
            'color' => '#26A5E4',
        ),
        array(
            'label' => 'واتساپ',
            'icon'  => 'whatsapp',
            'url'   => 'https://wa.me/09126803497',
            'color' => '#25D366',
        ),
        array(
            'label' => 'تماس',
            'icon'  => 'phone',
            'url'   => 'tel:+989126803497',
            'color' => '#7F53FF',
        ),
    );
}

function wafm_get_settings() {
    $defaults = array(
        'items'      => wafm_default_items(),
        'main_start' => '#7F53FF',
        'main_end'   => '#647DEE',
        'position'   => array( 'right' => 24, 'bottom' => 24 ),
    );
    $saved = get_option( 'wafm_settings' );
    if ( ! is_array( $saved ) ) return $defaults;
    return wp_parse_args( $saved, $defaults );
}

/* ============================================================
   2) آیکون‌ها (SVG داخلی - بدون نیاز به فایل جانبی)
   ============================================================ */
function wafm_icon_svg( $key ) {
    $icons = array(
        'rubika' => '<svg viewBox="0 0 24 24" fill="none"><path d="M12 3l7 4v10l-7 4-7-4V7l7-4z" stroke="currentColor" stroke-width="1.6" stroke-linejoin="round"/><circle cx="12" cy="12" r="2.6" fill="currentColor"/></svg>',
        'soroush' => '<svg viewBox="0 0 24 24" fill="none"><path d="M4 12c0-4.4 3.6-8 8-8s8 3.6 8 8-3.6 8-8 8c-1.3 0-2.5-.3-3.6-.9L4 20l1-4.5C4.4 14.4 4 13.2 4 12z" stroke="currentColor" stroke-width="1.6" stroke-linejoin="round"/></svg>',
        'telegram' => '<svg viewBox="0 0 24 24" fill="none"><path d="M21 4L3 11l6 2m12-9l-3.5 16L9 13m12-9L9 13m0 0l-1 6 3-3.4" stroke="currentColor" stroke-width="1.6" stroke-linejoin="round" stroke-linecap="round"/></svg>',
        'whatsapp' => '<svg viewBox="0 0 24 24" fill="none"><path d="M6 18l-1.5 3.5L8 20a8.5 8.5 0 104-1" stroke="currentColor" stroke-width="1.6" stroke-linecap="round" stroke-linejoin="round"/><path d="M8.5 8.7c0-.6.6-1.1 1.1-1.1.4 0 .6.2.7.5l.6 1.5c.1.3 0 .6-.2.8l-.5.5c.4.9 1.2 1.7 2.1 2.1l.5-.5c.2-.2.5-.3.8-.2l1.5.6c.3.1.5.3.5.7 0 .6-.5 1.1-1.1 1.1-3 0-6-3-6-6z" fill="currentColor"/></svg>',
        'phone' => '<svg viewBox="0 0 24 24" fill="none"><path d="M6.5 4h3l1.5 4-2 1.5a11 11 0 005.5 5.5L16 13l4 1.5v3a2 2 0 01-2.2 2C10.5 19 5 13.5 4.5 6.2A2 2 0 016.5 4z" stroke="currentColor" stroke-width="1.6" stroke-linejoin="round"/></svg>',
        'instagram' => '<svg viewBox="0 0 24 24" fill="none"><rect x="4" y="4" width="16" height="16" rx="5" stroke="currentColor" stroke-width="1.6"/><circle cx="12" cy="12" r="3.5" stroke="currentColor" stroke-width="1.6"/><circle cx="17" cy="7" r="1" fill="currentColor"/></svg>',
        'eitaa' => '<svg viewBox="0 0 24 24" fill="none"><path d="M4 12c0-4.4 3.6-8 8-8s8 3.6 8 8-3.6 8-8 8H4l1.6-3.2A7.9 7.9 0 014 12z" stroke="currentColor" stroke-width="1.6" stroke-linejoin="round"/></svg>',
        'link' => '<svg viewBox="0 0 24 24" fill="none"><path d="M9 15l6-6m-4-2l1.3-1.3a3 3 0 114.2 4.2L15 11m-6 2l-1.3 1.3a3 3 0 104.2 4.2L13 17" stroke="currentColor" stroke-width="1.6" stroke-linecap="round"/></svg>',
    );
    return isset( $icons[ $key ] ) ? $icons[ $key ] : $icons['link'];
}

function wafm_icon_choices() {
    return array(
        'rubika'    => 'روبیکا',
        'soroush'   => 'سروش پلاس',
        'telegram'  => 'تلگرام',
        'whatsapp'  => 'واتساپ',
        'phone'     => 'تماس / تلفن',
        'instagram' => 'اینستاگرام',
        'eitaa'     => 'ایتا',
        'link'      => 'لینک عمومی',
    );
}

/* ============================================================
   3) نمایش دکمه در فرانت (wp_footer)
   ============================================================ */
add_action( 'wp_footer', 'wafm_render_button' );
function wafm_render_button() {
    $settings = wafm_get_settings();
    $items    = array_filter( (array) $settings['items'], function( $it ) {
        return ! empty( $it['label'] ) && ! empty( $it['url'] );
    } );
    if ( empty( $items ) ) return;

    $right  = intval( $settings['position']['right'] );
    $bottom = intval( $settings['position']['bottom'] );
    ?>
    <style>
        #wafm-wrap{
            position:fixed; z-index:999999;
            right:<?php echo $right; ?>px; bottom:<?php echo $bottom; ?>px;
            font-family:inherit;
            direction:rtl;
        }
        #wafm-wrap *{ box-sizing:border-box; }
        #wafm-list{
            list-style:none; margin:0 0 16px; padding:0;
            display:flex; flex-direction:column; align-items:flex-start; gap:13px;
            opacity:0; visibility:hidden; transform:translateY(14px);
            transition:all .4s cubic-bezier(.34,1.56,.64,1);
        }
        #wafm-wrap.wafm-open #wafm-list{
            opacity:1; visibility:visible; transform:translateY(0);
        }
        #wafm-list li{
            display:flex; align-items:center; gap:10px;
            transform: translateX(16px) scale(.8);
            opacity:0; transition:all .35s cubic-bezier(.34,1.56,.64,1);
            width:100%;
            justify-content:flex-start;
        }
        #wafm-wrap.wafm-open #wafm-list li{
            transform: translateX(0) scale(1); opacity:1;
        }
        #wafm-list li:nth-child(1){transition-delay:.03s}
        #wafm-list li:nth-child(2){transition-delay:.07s}
        #wafm-list li:nth-child(3){transition-delay:.11s}
        #wafm-list li:nth-child(4){transition-delay:.15s}
        #wafm-list li:nth-child(5){transition-delay:.19s}
        #wafm-list li:nth-child(6){transition-delay:.23s}
        .wafm-row{
            display:flex; align-items:center; gap:10px;
            width:100%; text-decoration:none; cursor:pointer;
        }
        .wafm-item-btn{
            width:50px; height:50px; border-radius:50%;
            display:flex; align-items:center; justify-content:center;
            color:#fff; flex-shrink:0;
            box-shadow:0 8px 18px rgba(0,0,0,.2);
            border:2px solid rgba(255,255,255,.55);
            transition:transform .25s ease, box-shadow .25s ease;
        }
        .wafm-row:hover .wafm-item-btn{ transform:scale(1.12); box-shadow:0 10px 22px rgba(0,0,0,.28); }
        .wafm-row:hover .wafm-label{ box-shadow:0 8px 20px rgba(0,0,0,.2); }
        .wafm-item-btn svg{ width:22px; height:22px; }
        .wafm-label{
            background:rgba(255,255,255,.97); color:#222; font-size:13px; font-weight:600;
            width:96px; text-align:center;
            padding:9px 8px; border-radius:10px;
            box-shadow:0 6px 16px rgba(0,0,0,.14);
            backdrop-filter:blur(6px);
            white-space:nowrap; overflow:hidden; text-overflow:ellipsis;
        }
        #wafm-toggle{
            width:64px; height:64px; border-radius:50%; border:none; cursor:pointer;
            background:linear-gradient(135deg, <?php echo esc_attr($settings['main_start']); ?>, <?php echo esc_attr($settings['main_end']); ?>);
            box-shadow:0 10px 28px rgba(100,60,255,.4);
            display:flex; align-items:center; justify-content:center;
            position:relative; z-index:2;
            transition:transform .3s cubic-bezier(.34,1.56,.64,1);
        }
        #wafm-wrap.wafm-open #wafm-toggle{ transform:scale(1.06); }
        #wafm-toggle::before{
            content:""; position:absolute; inset:-6px; border-radius:50%;
            border:2px solid <?php echo esc_attr($settings['main_start']); ?>;
            opacity:.4; animation:wafm-pulse 2.2s ease-out infinite;
        }
        @keyframes wafm-pulse{
            0%{ transform:scale(.9); opacity:.5; }
            80%{ transform:scale(1.25); opacity:0; }
            100%{ opacity:0; }
        }
        #wafm-toggle svg{
            width:28px; height:28px; color:#fff;
            transition:transform .35s cubic-bezier(.4,0,.2,1);
        }
        #wafm-wrap.wafm-open #wafm-toggle svg{ transform:scale(.85) rotate(-8deg); }
        @media (max-width:480px){
            #wafm-wrap{ right:14px; bottom:14px; }
            #wafm-toggle{ width:58px; height:58px; }
            .wafm-label{ width:84px; font-size:12px; }
        }
    </style>

    <div id="wafm-wrap">
        <ul id="wafm-list">
            <?php foreach ( $items as $item ) :
                $color = ! empty( $item['color'] ) ? $item['color'] : '#7F53FF';
                ?>
                <li>
                    <a class="wafm-row" href="<?php echo esc_url( $item['url'] ); ?>" target="_blank" rel="noopener">
                        <span class="wafm-item-btn" style="background:<?php echo esc_attr( $color ); ?>">
                            <?php echo wafm_icon_svg( $item['icon'] ); ?>
                        </span>
                        <span class="wafm-label"><?php echo esc_html( $item['label'] ); ?></span>
                    </a>
                </li>
            <?php endforeach; ?>
        </ul>

        <button id="wafm-toggle" type="button" aria-label="باز کردن منوی ارتباط">
            <svg viewBox="0 0 24 24" fill="none"><path d="M4 13.5V12a8 8 0 0116 0v1.5" stroke="currentColor" stroke-width="1.8" stroke-linecap="round"/><rect x="3" y="13" width="4" height="6" rx="1.8" fill="currentColor"/><rect x="17" y="13" width="4" height="6" rx="1.8" fill="currentColor"/><path d="M9 20.5c0 .8 1.3 1.5 3 1.5s3-.7 3-1.5" stroke="currentColor" stroke-width="1.8" stroke-linecap="round"/></svg>
        </button>
    </div>

    <script>
        (function(){
            var wrap = document.getElementById('wafm-wrap');
            var btn  = document.getElementById('wafm-toggle');
            btn.addEventListener('click', function(){
                wrap.classList.toggle('wafm-open');
            });
            document.addEventListener('click', function(e){
                if ( ! wrap.contains(e.target) ) wrap.classList.remove('wafm-open');
            });
        })();
    </script>
    <?php
}

/* ============================================================
   4) پنل مدیریت در پیشخوان وردپرس
   ============================================================ */
add_action( 'admin_menu', 'wafm_admin_menu' );
function wafm_admin_menu() {
    add_menu_page(
        'دکمه شناور',
        'دکمه شناور',
        'manage_options',
        'wafm-settings',
        'wafm_admin_page',
        'dashicons-share',
        58
    );
}

add_action( 'admin_init', 'wafm_handle_save' );
function wafm_handle_save() {
    if ( ! isset( $_POST['wafm_save'] ) ) return;
    if ( ! current_user_can( 'manage_options' ) ) return;
    if ( ! isset( $_POST['wafm_nonce'] ) || ! wp_verify_nonce( $_POST['wafm_nonce'], 'wafm_save_action' ) ) return;

    $items = array();
    if ( isset( $_POST['wafm_label'] ) && is_array( $_POST['wafm_label'] ) ) {
        foreach ( $_POST['wafm_label'] as $i => $label ) {
            $label = sanitize_text_field( $label );
            $url   = isset( $_POST['wafm_url'][ $i ] ) ? esc_url_raw( $_POST['wafm_url'][ $i ] ) : '';
            $icon  = isset( $_POST['wafm_icon'][ $i ] ) ? sanitize_text_field( $_POST['wafm_icon'][ $i ] ) : 'link';
            $color = isset( $_POST['wafm_color'][ $i ] ) ? sanitize_hex_color( $_POST['wafm_color'][ $i ] ) : '#7F53FF';
            if ( $label === '' && $url === '' ) continue;
            $items[] = array(
                'label' => $label,
                'url'   => $url,
                'icon'  => $icon,
                'color' => $color ? $color : '#7F53FF',
            );
        }
    }

    $settings = array(
        'items'      => $items,
        'main_start' => sanitize_hex_color( $_POST['wafm_main_start'] ) ?: '#7F53FF',
        'main_end'   => sanitize_hex_color( $_POST['wafm_main_end'] ) ?: '#647DEE',
        'position'   => array(
            'right'  => intval( $_POST['wafm_right'] ),
            'bottom' => intval( $_POST['wafm_bottom'] ),
        ),
    );

    update_option( 'wafm_settings', $settings );
    add_action( 'admin_notices', function(){
        echo '<div class="notice notice-success is-dismissible"><p>تنظیمات دکمه شناور با موفقیت ذخیره شد.</p></div>';
    } );
}

function wafm_admin_page() {
    if ( ! current_user_can( 'manage_options' ) ) return;
    $settings = wafm_get_settings();
    $items    = $settings['items'];
    $icons    = wafm_icon_choices();
    ?>
    <div class="wrap" dir="rtl" style="font-family:inherit;">
        <h1 style="display:flex;align-items:center;gap:8px;">مدیریت دکمه شناور شبکه‌های اجتماعی</h1>
        <p style="color:#666;">آیتم‌های زیر همان دکمه‌هایی هستند که در سایت روی دکمه شناور نمایش داده می‌شوند.</p>

        <form method="post">
            <?php wp_nonce_field( 'wafm_save_action', 'wafm_nonce' ); ?>

            <h2 class="title">تنظیمات ظاهری دکمه اصلی</h2>
            <table class="form-table">
                <tr>
                    <th>رنگ شروع گرادیان</th>
                    <td><input type="color" name="wafm_main_start" value="<?php echo esc_attr( $settings['main_start'] ); ?>"></td>
                </tr>
                <tr>
                    <th>رنگ پایان گرادیان</th>
                    <td><input type="color" name="wafm_main_end" value="<?php echo esc_attr( $settings['main_end'] ); ?>"></td>
                </tr>
                <tr>
                    <th>فاصله از راست (px)</th>
                    <td><input type="number" name="wafm_right" value="<?php echo esc_attr( $settings['position']['right'] ); ?>" style="width:100px;"></td>
                </tr>
                <tr>
                    <th>فاصله از پایین (px)</th>
                    <td><input type="number" name="wafm_bottom" value="<?php echo esc_attr( $settings['position']['bottom'] ); ?>" style="width:100px;"></td>
                </tr>
            </table>

			<p>ساخته شده توسط علیرضا رحمتی | اینستاگرام : alireza.webcode | تلگرام : alireza_webcode</p>
            <h2 class="title">آیتم‌های منو</h2>
            <table class="widefat" id="wafm-table" style="max-width:900px;">
                <thead>
                    <tr>
                        <th style="width:22%">عنوان</th>
                        <th style="width:16%">آیکون</th>
                        <th style="width:34%">لینک</th>
                        <th style="width:12%">رنگ</th>
                        <th style="width:8%">حذف</th>
                    </tr>
                </thead>
                <tbody id="wafm-rows">
                    <?php foreach ( $items as $item ) : ?>
                        <tr>
                            <td><input type="text" name="wafm_label[]" value="<?php echo esc_attr( $item['label'] ); ?>" class="regular-text" placeholder="مثلا: تلگرام"></td>
                            <td>
                                <select name="wafm_icon[]">
                                    <?php foreach ( $icons as $key => $name ) : ?>
                                        <option value="<?php echo esc_attr( $key ); ?>" <?php selected( $item['icon'], $key ); ?>><?php echo esc_html( $name ); ?></option>
                                    <?php endforeach; ?>
                                </select>
                            </td>
                            <td><input type="text" name="wafm_url[]" value="<?php echo esc_attr( $item['url'] ); ?>" class="regular-text" placeholder="https://..."></td>
                            <td><input type="color" name="wafm_color[]" value="<?php echo esc_attr( $item['color'] ); ?>"></td>
                            <td><button type="button" class="button wafm-remove-row">حذف</button></td>
                        </tr>
                    <?php endforeach; ?>
                </tbody>
            </table>

            <p><button type="button" class="button" id="wafm-add-row">+ افزودن آیتم جدید</button></p>

            <?php submit_button( 'ذخیره تنظیمات', 'primary', 'wafm_save' ); ?>
        </form>
    </div>

    <script>
        (function(){
            var iconOptions = <?php echo wp_json_encode( $icons ); ?>;
            document.getElementById('wafm-add-row').addEventListener('click', function(){
                var tbody = document.getElementById('wafm-rows');
                var tr = document.createElement('tr');
                var opts = '';
                for ( var key in iconOptions ) {
                    opts += '<option value="'+key+'">'+iconOptions[key]+'</option>';
                }
                tr.innerHTML =
                    '<td><input type="text" name="wafm_label[]" class="regular-text" placeholder="عنوان"></td>' +
                    '<td><select name="wafm_icon[]">'+opts+'</select></td>' +
                    '<td><input type="text" name="wafm_url[]" class="regular-text" placeholder="https://..."></td>' +
                    '<td><input type="color" name="wafm_color[]" value="#7F53FF"></td>' +
                    '<td><button type="button" class="button wafm-remove-row">حذف</button></td>';
                tbody.appendChild(tr);
            });
            document.getElementById('wafm-rows').addEventListener('click', function(e){
                if ( e.target.classList.contains('wafm-remove-row') ) {
                    e.target.closest('tr').remove();
                }
            });
        })();
    </script>
    <?php
}

طراحی و تهیه‌شده برای وب‌سایت امیر بهارزاده

دسته‌ها: مقالات طراحی سایت