add custom shortcode to shortcode generator

resolved (8 posts) (3 voices)

  1. mmjaeger
    Member

    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!!

    Posted 10 months ago #
  2. Elliott
    Support

    Hello mmjaeger,

    In your child theme try creating a directory like this,

    /lib/shortcodes/[your_shortcode].php

    If that does not work then you may need to load it manually in your functions.php file.

    Posted 10 months ago #
  3. mmjaeger
    Member

    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 there

    Posted 10 months ago #
  4. Elliott
    Support

    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 #
  5. mmjaeger
    Member

    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 #
  6. 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 #
  7. Elliott
    Support

    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 #
  8. 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.

Construct WordPress Theme
Construct wordpress theme
Myriad WordPress Theme
Myriad wordpress theme
Method WordPress Theme
Method wordpress theme
Fusion WordPress Theme
Fusion wordpress theme
Elegance WordPress Theme
Elegance wordpress theme
Echelon WordPress Theme
Echelon wordpress theme
Dejavu WordPress Theme
Dejavu wordpress theme
Modular WordPress Theme
Modular wordpress theme