Created
September 6, 2022 00:56
-
-
Save Tmeister/93f85616f71f59ff1f98bd97909a3000 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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