1

I made a heading shortcode

Here it is:

function heading( $atts, $content = null ) {
    // [head][/head]
    $atts = shortcode_atts( array(), $atts, 'head' );

    // do shortcode actions here
    $output = "<h1 class=\"banner-heading update-\">".$content."</h1>";
    return $output;
}
add_shortcode( 'head','heading' );

What I want:

I want to increment my update class dynamically when ever I write the shortcode in the editor. Something like this update-0, update-1 etc.

UPDATED:

function heading( $atts, $content = null ) {
    // [head][/head]
    static $instance = 0;
    $atts = shortcode_atts( array(), $atts, 'head' );

    // do shortcode actions here
    $output = "<h1 class=\"banner-heading update-."$instance"\">".$content."</h1>";
    $instance++;
    return $output;

}
add_shortcode( 'head','heading' );

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.