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

Dynamically create shortcodes using add_shortcode and a callback

the shortcodes doesn’t shop up in the liste because it’s not a valid declaration with a valid function callback on the 2nd argument try this to see what append : // shortcode data add_filter(“shortcode_list”, function ($shortcode_list) { $shortcode_list[“slugA”] = array( “html” => “test html 1”, ); return $shortcode_list; }); add_filter(“shortcode_list”, function ($shortcode_list) { $shortcode_list[“slugB”] = … Read more

WordPress shortcodes & performance

You need to look at this from a couple of perspectives and then you have to weigh the odds against each other In general, shortcodes will be slower (we are talking milliseconds here) as they need to be parsed and processed by the shortcode handler. USAGE: [my_shortcode] in post editor Shortcodes in general are quite … Read more

Can a shortcode function this way

Yes. That result can be achieved by single shortcode function. Here is your code- function paragraph_shortcode( $atts, $content = null ) { $pull_atts = shortcode_atts( array( ‘value’ => 0 ), $atts ); return ‘You are reading paragraph ‘ . wp_kses_post( $pull_atts[ ‘value’ ] ) . ‘: ‘ . do_shortcode($content); } add_shortcode( ‘paragraph’, ‘paragraph_shortcode’ ); It’ll … Read more

How can I get the current user email instead of user ID?

you can get all logged in users details by below function <?php $current_user = wp_get_current_user(); /** * @example Safe usage: $current_user = wp_get_current_user(); * if ( !($current_user instanceof WP_User) ) * return; */ echo ‘Username: ‘ . $current_user->user_login . ‘<br />’; echo ‘User email: ‘ . $current_user->user_email . ‘<br />’; echo ‘User first name: ‘ … Read more