Editing shortcodes to add functionality
-
I use a theme (DICE) that has not been updated in a loooong time. Until I can devote the time for a full site redesign, we will continue using DICE.
I am working on getting some dynamically-generated page content using PHP/ajax. The php function will be called from a button click. I have got it to work perfectly, assuming I use the <button onclick=”func()”> syntax, but the moment I attempt to go deeper and use the shortcode button that we use for all of the buttons on the site, the button quits working to call the function.
How could I make it so that this button shortcode would support that PHP/ajax/javascript onclick=func() argument?
<?php function btp_button_shortcode($atts, $content = null) { extract( shortcode_atts( array( 'href' => '#', 'priority' => 'primary', 'size' => 'small', 'wide' => false, 'title' => '', 'linking' => 'default', ), $atts ) ); if ( !strlen( $href ) || $linking == 'none') { return ''; } /* Compose output */ $out = ''; $rel = ''; $class = ''; $class .= 'button ' . $priority . ' ' . $size . ' '; $class .= $wide ? 'wide ' : ''; switch ( $linking ) { case 'lightbox': $rel .= 'prettyPhoto '; break; case 'new_window': case 'new-window': $class .= 'new-window '; break; default: break; } $out .= '<a class="' . esc_attr( $class ) . '" '; $out .= 'href="' . esc_url( $href ) . '" '; $out .= 'title="' . esc_attr( $title ) . '" '; $out .= 'rel="' . esc_attr( $rel ) . '"'; $out .= '><span>' . esc_html( $content ) . '</span></a>'; return $out; } ?>
- The topic ‘Editing shortcodes to add functionality’ is closed to new replies.