5

In below example, I wrapped [contact-form-7 id="33"] inside another shortcode [myform]. So, when posting, just use [myform] istead:

function wrapthecode() {
    return do_shortcode('[contact-form-7 id="33"]');
}
add_shortcode( 'myform', 'wrapthecode' );

But how to append variable ID on the new shortcode?

Means [myform id="33"] is [contact-form-7 id="33"] and [myform id="34"] is [contact-form-7 id="34"]

8

You need to get the attributes of the shortcode, which is quite simple and documented in the add_shortcode() examples:

function wrapthecode( $attr ) {
    if( empty( $attr['id'] ) )
        return 'No ID given.';

    return do_shortcode('[contact-form-7 id="' . $attr['id'] . '"]');
}
add_shortcode( 'myform', 'wrapthecode' );
| improve this answer | |

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.