AMZ

WPTurbo » Snippets » AMZ
0

Created with:

Visibility: 

public

Creator: diecgor@gmail.com

Customize with WPTurbo AI
X

Add Snippet To Project

New Project
Add To Existing Project
					<?php

namespace WPTurbo;

use WP_Turbo;

if ( ! defined( 'ABSPATH' ) ) {
    exit; // Exit if accessed directly.
}

/**
 * Adds a shortcode to display an Amazon affiliate link for Amazon Spain with a search query.
 *
 * @param array $atts Shortcode attributes.
 * @return string HTML link styled as a button with the affiliate ID.
 */
function wpturbo_amazon_affiliate_link( $atts ) {
    $atts = shortcode_atts( [
        'search' => '',
        'text'   => 'Compra en Amazon',
    ], $atts, 'amazon_affiliate' );

    $affiliate_id = 'tu_afiliado_id'; // Reemplaza esto con tu ID de afiliado de Amazon.

    if ( '' === $atts['search'] ) {
        return '';
    }

    $search_query = urlencode( $atts['search'] );
    $url = "https://www.amazon.es/s?k={$search_query}&tag={$affiliate_id}";

    $button_style = "display: inline-block; padding: 10px 20px; color: #fff; background-color: #ff9900; text-align: center; text-decoration: none; border-radius: 5px;";

    return "<a href="{$url}" target="_blank" rel="nofollow" style="{$button_style}">{$atts['text']}</a>";
}
add_shortcode( 'amazon_affiliate', 'WPTurbowpturbo_amazon_affiliate_link' );
				

Este código realiza los siguientes cambios:

Ahora, cuando utilices el shortcode en tus posts, el enlace se verá como un botón:

Este enlace se mostrará como un botón con fondo naranja (#ff9900), texto blanco, y bordes redondeados, haciendo que sea más llamativo para los usuarios.

Register an account to save your snippets or go Pro to get more features.