Dies ist ein bisschen spät für die Antwort-Partei, aber ich sehe diesen Beitrag, wenn ich benutzerdefinierte Shortcodes zu meinen Formularen und Nachrichtentext hinzufügen möchte. Ich wollte Shortcodes einfügen können, ohne sie speziell in CF7 und oft nur im Nachrichtentext zu registrieren (etwas, was CF7 nicht zu tun scheint).
Hier ist, wie ich es endlich tat:
// Allow custom shortcodes in CF7 HTML form
add_filter('wpcf7_form_elements', 'dacrosby_do_shortcodes_wpcf7_form');
function dacrosby_do_shortcodes_wpcf7_form($form) {
$form = do_shortcode($form);
return $form;
}
// Allow custom shortcodes in CF7 mailed message body
add_filter('wpcf7_mail_components', 'dacrosby_do_shortcodes_wpcf7_mail_body', 10, 2);
function dacrosby_do_shortcodes_wpcf7_mail_body($components, $number) {
$components['body'] = do_shortcode($components['body']);
return $components;
};
// Add shortcode normally as per WordPress API
add_shortcode('my_code', 'my_code_callback');
function my_code_callback($atts){
extract(shortcode_atts(array(
'foo' => 'bar'
), $atts));
// do things
return $foo;
}
Ich benutze eine einfachere Version für meine Bedürfnisse: 'wpcf7_add_shortcode ('input_name', Funktion ($ tag) {return ' '}); ' – vladkras