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

How to: How do I make my own shortcodes without plugins?

You’ll probably need to modify this a bit to ensure things get placed where you want them but here’s something I wrote that counts views on posts and displays the view counts for administrators: //ADD TRACKER FUNCTION TO ALL SINGLE VIEWS function custom_hook_tracker( $post_id ) { if( !is_single() ) return; if( empty( $post_id ) ) … Read more

Shortcode But Without The Equals Sign?

Try this: function font_fam($atts, $content = null) { extract(shortcode_atts(array( ‘f’ => isset($atts[0]) ? $atts[0] : ” , ), $atts)); return ‘<span style=”font-family:’ . $f . ‘”>’ . $content . ‘</span>’; } add_shortcode (‘f’,’font_fam’);

Audio tags around Mp3 URL in content

Filter the_content ond/or the_excerpt and replace audio URLs that are not an attribute value already. Example: add_filter( ‘the_content’, ‘wpse_82336_audio_url_to_shortcode’, 1 ); add_filter( ‘the_excerpt’, ‘wpse_82336_audio_url_to_shortcode’, 1 ); function wpse_82336_audio_url_to_shortcode( $content ) { # See http://en.wikipedia.org/wiki/Audio_file_format # Adjust the list to your needs $suffixes = array ( ‘3gp’, ‘aa3’, ‘aac’, ‘aiff’, ‘ape’, ‘at3’, ‘au’, ‘flac’, ‘m4a’, ‘m4b’, … Read more

how to remove filter from wordpress shortcode output

Filters on the_content are not applied on a “per shortcode” basis. Post content is passed to the first filter, and then the altered post content is passed to the second filter, and then the content altered by the first two filters is passed to the third, and so on. You can’t remove a the_content filter, … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)