El código para crear los shortcode se pueden adicionar en el archivo function.php de nuestra plantilla, o creando un plugin y adicionándolo en la sección plugin de wordpress.
En wordpress [nombredelshortcode]
 
// Add Shortcode
function custom_shortcode() {
}
add_shortcode( 'nombredelshortcode', 'custom_shortcode' );
Los Shortcode recibe dos parámetros variables y contenido. Esta es la forma de adicionar un shortcode en una página o post de wordpress con variables y contenidos.
[nombreshortcode nombrevariable1=valor nombrevariable2=valor]contenido[/nombreshortcode]
 
// Add Shortcode
function custom_shortcode($variables, $contenido) {
   
    // imprime las variables 
    print "Primera variable ".$variables['nombrevariable1']." Segunda variable ".$variables['nombrevariable2']: 
   // imprime el contenido
   
    print $contenido
}
add_shortcode( 'nombredelshortcode', 'custom_shortcode' );
Para nuestro caso si deseamos anidar dos shortcode, se debe definir los dos shortcode con su respectiva función, en el shortcode contenedor el contenido se imprime ejecutando la función do_shortcode() .
[cwcontenedor] [cwpintarboton url='#'][cwpintarboton url='#'][/cwcontenedor] 

 
// shortcode contenedor de botones 
add_shortcode( 'cwcontenedor', 'funcioncwcontenedor' );
function funcioncwcontenedor( $variables, $contenido = null ) {             
        $html .= '';
        $html .= do_shortcode( $contenido );   // anidados agregados en el contenido     
        $html .= '';
        print $html; 
}
// shortcode botones 
add_shortcode( 'cwpintarboton ', 'funcioncwpintarboton' );
function funcioncwpintarboton( $variables, $contenido = null ) {             
        $boton .= 'Botón';
       
        print $boton; 
}
 
No hay comentarios
Publicar un comentario
Desea contactar con nosotros, deje un comentario y pronto le daremos respuesta.