Is there a way to parse shortcodes in PHP?
You can execute shortcodes using the do_shortcode() function $gallery_html = do_shortcode(”);
You can execute shortcodes using the do_shortcode() function $gallery_html = do_shortcode(”);
There are no filter hook called captiontag. You can change the value of the caption html tag by specifying the captiontag option when inserting the shortcode. From the gallery shortcode codex page: captiontag the name of the XHTML tag used to enclose each caption. The default is “dd”. For example, to change the gallery markup … Read more
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’ );
A shortcode has to return just a string, you should not print something like in wp_list_pages() or echo. From Shortcode API: The return value of a shortcode handler function is inserted into the post content output in place of the shortcode macro. Remember to use return and not echo – anything that is echoed will … Read more
I think you could get around this by pre-running the shortcodes on the page by applying the content filters before the header is output. This should allow any internal shortcodes run inside the included post to add any action hooks properly and thus any needed stylesheets/resources. add_action(‘wp_loaded’,’maybe_prerun_shortcodes’); function maybe_prerun_shortcodes() { if (is_page()) { global $post; … Read more
Based on Toms comment this will work: <?php echo do_shortcode( ‘ [vc_column_text] <h3><a href=”https://wordpress.stackexchange.com/questions/298984/home”>home</a></h3> [/vc_column_text] ‘ );?>
The shortcode functions just return a value, you need to echo or assign it to something. <?php echo do_shortcode(‘[div]’); ?>
It seems you are working on the wrong end. Try sanitizing the user input, for instance by means of sanitize_text_field, not the shortcode output.
Shortcode functions are only called when the content of the visual editor is processed and displayed, so nothing in your shortcode function will run early enough. Have a look at the has_shortcode function. If you hook in early enough to send headers and late enough for the query to be set up you can check … Read more
Hope this helps someone: Instead of doing this: <a href=”https://example.com/folder/edit.php?action=someaction&id=[foocode parameter=”value”]&edittoken=[foocode parameter=”othervalue”]”>linktext</a> You can do this: [foocode parameter1=value parameter2=othervalue] and then do this: add_shortcode( ‘foocode’, ‘prefix_foocode’ ); function prefix_foocode( $atts ) { // Normalize $atts, set defaults and do whatever you want with $atts. $html=”<a href=”https://example.com/folder/edit.php?action=someaction&id=” . $atts[‘parameter1′] .’&edittoken=’ . $atts[‘parameter2’] . ‘”>linktext</a>’; return $html; … Read more