Hello
I'd like to add a custom shortcode to the shortcode generator using a child theme as I don't want to touch the parent theme installation at all - are there any instructions - could you please tell me how to proceed, please. if I dump my custom shortcode file into the infocus lib/shortcodes main directory, everything works but I'd rather have it in my child-theme directory!!
add custom shortcode to shortcode generator
(8 posts)
(3 voices)
-
Posted 10 months ago #
-
Hello mmjaeger,
In your child theme try creating a directory like this,
/lib/shortcodes/[your_shortcode].phpIf that does not work then you may need to load it manually in your functions.php file.
Posted 10 months ago # -
Hello Elliott
I'm able to load the shortcodes - however, they don't show up in the drop-down of the shortcode generator - would be nice if a user could add some custom shortcodes therePosted 10 months ago # -
Make sure that your shortcode file is named in the format of "00-shortcode.php". You may need to paste it inside the actual theme folder and not a child theme.
I haven't tested it with a child theme yet but I'll look into it.
Posted 10 months ago # -
Sounds good to me - I really like to keep things together in the child-theme to keep a clean upgrade path - I guess that's the purpose of the child-theme, isn't it.
Posted 10 months ago # -
Hi Elliott,
placing a customised shortcode file in the child folder doesn't work. That somehow defeats the object of a child theme, also if the skin isn't available in the skin selector.
Also, if I make changes to say 02-buttons, do I just have the changed function in there or the entire orginal 02-buttons, only with my additions/changes?
Cheers,
Helmar
Posted 5 months ago # -
Hello helmar,
Add this inside your child theme's functions.php file,
add_shortcode('button_custom', 'button_custom'); function button_custom() { extract(shortcode_atts(array( 'size' => '', 'align' => '', 'link' => '#', 'target' => '', 'variation' => '', 'bgcolor' => '', 'textcolor' => '' ), $atts)); $size = ( $size == 'large' ) ? ' large_button' : $size; $size = ( $size == 'medium' ) ? ' medium_button' : $size; $size = ( $size == 'small' ) ? ' small_button' : $size; $align = ( $align ) ? ' align'.$align : ''; $target = ( $target == 'blank' ) ? ' target_blank' : ''; $variation = ( ( $variation ) && ( empty( $bgcolor ) ) ) ? ' ' . $variation : ''; $styles = array(); if( $bgcolor ) $styles[] = 'background-color:' . $bgcolor . ';border-color:' . $bgcolor . ';'; if( $textcolor ) $styles[] = 'color:' . $textcolor . ';'; $style = join( '', array_unique( $styles ) ); $style = !empty( $style ) ? ' style="' . $style . '"': '' ; $out = '<a href="' . esc_url( $link ) . '" class="button_link hover_fade' . $size . $target . $align . $variation . '"' . $style . '><span>' . mysite_remove_wpautop( $content ) . '</span></a>'; return $out; }And you can do whatever changes you need to it there and use it like this,
[button_custom]my text[/button_custom]Posted 5 months ago # -
Hi Elliott,
the thing with buttons in general is that they lack both CLASS and TITLE attributes. Maybe add this for a future release, because with the CLASS attribute I can for instance use a button to open a lightbox, and the TITLE attribute is self-explanatory.
extract(shortcode_atts(array( 'class' => '', 'title' => '', 'size' => '', 'align' => '', 'link' => '#', 'target' => '', 'variation' => '', 'bgcolor' => '', 'textcolor' => '' ), $atts)); $size = ( $size == 'large' ) ? ' large_button' : $size; $size = ( $size == 'medium' ) ? ' medium_button' : $size; $size = ( $size == 'small' ) ? ' small_button' : $size; $align = ( $align ) ? ' align'.$align : ''; $class = ($class) ? ' '.$class: ''; $title = ($title) ? ' '.$title: ''; $target = ( $target == 'blank' ) ? ' target_blank' : ''; $variation = ( ( $variation ) && ( empty( $bgcolor ) ) ) ? ' ' . $variation : ''; $styles = array(); if( $bgcolor ) $styles[] = 'background-color:' . $bgcolor . ';border-color:' . $bgcolor . ';'; if( $textcolor ) $styles[] = 'color:' . $textcolor . ';'; $style = join( '', array_unique( $styles ) ); $style = !empty( $style ) ? ' style="' . $style . '"': '' ; $out = '<a href="' . esc_url( $link ) . '" title="' .$title. '"><span>' . mysite_remove_wpautop( $content ) . '</span></a>'; return $out; }
Helmar
Posted 3 months ago #
Reply
You must log in to post.













