WordPress.org

Ready to get started?Download WordPress

Forums

First Plugin. PHP Beginner. (2 posts)

  1. Agrajag27
    Member
    Posted 7 months ago #

    Guys,

    I created my first shortcode function and placed it in functions.php.

    That works fine but I want to get it out of there so that I can more easily update my theme without having to worry about it getting lost.

    We run mainly a movie review site and this allows us to easily add stars to various elements of our site. Would someone be willing to lay out what I need to do to get this into a plugin? The biggest confusion is that I'm not seeing a way to handled the specific shortcode reference in plugin examples I'm seeing. Here's the very simple code:

    /**
    Stars shortcode
    */

    function stars_image( $atts ) {

    // Attributes
    extract( shortcode_atts(
    array(
    'rating' => '0',
    'set' => '',
    ), $atts )
    );

    // Code
    return '<img src="http://slashcomment.com/images/' . $set . 'star-' . $rating . '.png' . '"/>  ';
    }
    add_shortcode( 'stars', 'stars_image' );

    -------------------------------------------------

    Any help would be greatly appreciated. I'm looking to use this as a "hello world" type example to build from.

  2. Agrajag27
    Member
    Posted 7 months ago #

    /**
     * Stars shortcode
     *
    */
    
    function stars_image( $atts ) {
    
    	// Attributes
    	extract( shortcode_atts(
    		array(
    			'rating' => '0',
    			'set' => '',
    		), $atts )
    	);
    
    	// Code
    	return '<img src="http://slashcomment.com/images/' . $set . 'star-' . $rating . '.png' . '"/> &nbsp;';
    }
    add_shortcode( 'stars', 'stars_image' );

Reply

You must log in to post.

About this Topic

Tags

No tags yet.