Skip to content

Instantly share code, notes, and snippets.

@Tmeister
Created September 6, 2022 00:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Tmeister/93f85616f71f59ff1f98bd97909a3000 to your computer and use it in GitHub Desktop.
Save Tmeister/93f85616f71f59ff1f98bd97909a3000 to your computer and use it in GitHub Desktop.
<?php
add_shortcode('the_shortcode_tag', function($atts){
// En $attts vienen todos tus attributos en forma de array
// Aqui solo verificas tus attributos, y si no existen, le asignas un valor por defecto
$atts = shortcode_atts([
'atributo1' => 'valor por defecto 1',
'atributo2' => 'valor por defecto 2',
], $atts);
// Ahora puedes acceder a tus atributos como si fueran variables
echo $atts['atributo1'] . ' ' . $atts['atributo2'];
});
// Esto imprime valor 1 valor 2
do_shortcode('[the_shortcode_tag atributo1="valor1" atributo2="valor2"]');
// Esto imprime valor 1 valor por defecto 2
do_shortcode('[the_shortcode_tag atributo1="valor1"]');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment