WordPress.org

Ready to get started?Download WordPress

Forums

Mini Loops
[resolved] Adding Shortcodes ? (3 posts)

  1. sugardaddy
    Member
    Posted 1 year ago #

    I'm trying to add some new shortcodes but it's not interpreted.
    In fact, I'm using KIA Subtitle which add a subtitle field (just under the title and that's better for my user than a custom field) and is accessible with the_subtitle or get_the_subtitle functions.
    I know I could achieve that with custom fields... but I'm curious to know why my try failed. Here is the code I add to helpers.php :

    add_shortcode( 'ml_subtitle' , 'miniloop_subtitle' );
    function miniloop_subtitle( $atts ) {
    	extract( shortcode_atts( array(
    		'length' => 0, //characters
    		'before' => '',
    		'after' => '',
    	), $atts ) );
    	$subtitle = apply_filters( 'the_subtitle', get_the_subtitle() );
    
    	if ($length)
    		$subtitle = substr( $subtitle, 0, $length );
    
    	$subtitle = $before . $subtitle . $after;
    
    	return $subtitle;
    }

    Thanks for your help !

    http://wordpress.org/extend/plugins/mini-loops/

  2. sugardaddy
    Member
    Posted 1 year ago #

    any idea ? (back from vacation)

  3. sugardaddy
    Member
    Posted 1 year ago #

    This code is incorrect... I forget something very important.

    $subtitle = apply_filters( 'the_subtitle', get_the_subtitle($post_id) );

    It works like a charm !

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic