How do I hardcode a WordPress shortcode into my theme?

Check out do_shortcode(): http://codex.wordpress.org/Function_Reference/do_shortcode do_shortcode(‘[shortcode option1=”value1″ option2=”value2″]’); So your example would be: do_shortcode(‘[post_comments]’); What might be easier is to tap into the underlying comment functions: http://codex.wordpress.org/Function_Reference/comments_number <p> This post currently has <?php comments_number( ‘no responses’, ‘one response’, ‘% responses’ ); ?>. </p> You can also use get_comments_number which returns the value rather than printing it … Read more

get attributes/part of the gallery shortcode

The task It’s not as easy, as it looks at a first glance. The main problem is, that you can define your own shortcode and simply override the default. Actually that’s what some themes are doing (blame you ThemeForest authors!). In this case, simply hooking into post_gallery won’t work in every case. Drawbacks for post_gallery … Read more

Using shortcodes to parse POST request (containing the data from a front-end form)

Alway send submissions to the page the form is displayed. In your shortcode callback you can then display proper error or success messages. Sample: add_shortcode( ‘classifiedsform’, ‘classifiedsform_callback’ ); function classifiedsform_callback() { if ( ‘POST’ !== $_SERVER[‘REQUEST_METHOD’] or ! isset ( $_POST[‘classifieds’] ) ) { return classifieds_input_form(); } // process input show errors or success message … Read more

I dont want to show shortcode in tag

A) If you want to show the shortcode syntax you can try to write it with double brackets in the editor: <pre>[[shortcode foo=”bar”]]</pre> It will then display as <pre>[shortcode foo=”bar”]</pre> on your frontend and it will not activate the shortcode callback. B) Or if you want some extra formatting, you could define your own pretty … Read more

Shortcode output is screwed up when arrow symbol “

This issue was introduced in WP 4.2.3 with the introduction of the do_shortcodes_in_html_tags() function, which does a HTML parse of content to protect against content containing shortcodes authored by untrustworthy contributors/authors who by specially crafting shortcode attributes can create XSS exploits. If that security situation doesn’t apply to you and you only want this to … Read more

How do I require a file in a shortcode?

Shortcodes are expected to return content, not echo it out. So if your shortcode_file.php file is straight html, it’s considered being echoed. If that’s the case, you could do something like : function shortcode_name(){ ob_start(); require_once ( plugin_dir_path(__FILE__) . ‘/shortcode_file.php’); $content = ob_get_clean(); return $content; };

Changing playlist shortcode thumbnail sizes?

Demo Plugin – Fixed Size Here’s one suggestion as a demo plugin (PHP 5.4+): <?php /* Plugin Name: Custom Playlist Thumb Size */ namespace WPSE238646\PlaylistThumbSize; add_shortcode( ‘playlist’, function( $atts = [], $content=”” ) { add_filter( ‘wp_get_attachment_image_src’, __NAMESPACE__ . ‘\\src’ , 10, 3 ); $out = wp_playlist_shortcode( $atts, $content ); remove_filter( ‘wp_get_attachment_image_src’, __NAMESPACE__ . ‘\\src’ ); … Read more

How to put an “include” inside a “do_shortcode”?

You won’t be able to concatenate an include as it doesn’t return a string. What you could do is store that include content in a variable, and then concatenate. ob_start(); include ‘incMac.php’; $include_content = ob_get_clean(); echo do_shortcode( ‘[student]’ . $include_content . ‘[/student]’ ); ob_start tells php to store the output from the script in an … Read more