How to display a shortcode caption somewhere other than the_content

Try this: $caption_info = array(); add_filter( ‘img_caption_shortcode’, ‘capture_caption’, 10, 3 ); function capture_caption( $blank = ”, $attr, $content ) { global $caption_info; $caption_info[] = array(‘attr’ => $attr, ‘content’ => $content ); return ‘ ‘; } It will save info from all captions into global $caption_info variable and suppress their display in content (space is returned … Read more

shortcode to create dynamic dropdown box form shortcode attributes

Based on your example at the bottom of your question, and your statement that you would like something like that for readability, I’d do something like this: function dropdown_option($atts) { $dropid = (isset($atts[‘dropid’])) ? $atts[‘dropid’] : ”; global $sco_array; if (!empty($atts[‘value’]) && !empty($atts[‘text’])) { $sco_array[$dropid][$atts[‘value’]] = $atts[‘text’]; } } add_shortcode(‘sco’,’dropdown_option’); function sc_dropdown($atts) { $id = … Read more

Stripping shortcode from custom excerpt function

Don’t use a custom function. You should use the hooks. You don’t have to strip shortcodes, wordpress does that for you automatically, just use something like this // setting higher priority so that wordpress default filter have already applied add_filter(‘the_excerpt’, ‘custom_excerpt_filter’, 11); function custom_excerpt_filter($excerpt) { // apply your logic of read more link here return … Read more

Return vs Echo Shortcode

Just define a variable, and concat all html as string and return it. <?php function services_shortcode( $atts ) { // Attributes extract( shortcode_atts( array( ‘slug’ => ”, ), $atts ) ); $html=””; if ( isset( $slug ) ) { $args = array( ‘post_type’ => ‘cbd_services’, ‘name’ => $slug ); // -1 Shows ALL Posts $loop … Read more

Getting the count of a shortcode that is nested

Here is very, very rough code that should get you started: add_shortcode(‘outer_shortcode’,function($attts,$content){return 1;}); add_shortcode(‘inner_code’,function($attts,$content){return 1;}); $str=”[outer_shortcode][inner_code url=”#” title=”Hello”][inner_code url=”#2″ title=”Hello2″][/outer_shortcode]”; $reg = get_shortcode_regex(); preg_match_all(‘~’.$reg.’~’,$str,$matches); var_dump($matches); preg_match_all(‘~’.$reg.’~’,$matches[5][0],$matches2); var_dump($matches2); What is happening is that you are parsing the string which matches and “pulls apart” the outer shortcode. You then need to parse that shortcode’s content (array element … Read more

Counting number of posts in a category and its sub categories and displaying result using shortcode

The shortcode // Add Shortcode to show posts count inside a category function category_post_count( $atts ) { $atts = shortcode_atts( array( ‘category’ => null ), $atts ); // get the category by slug. $term = get_term_by( ‘slug’, $atts[‘category’], ‘category’); return ( isset( $term->count ) ) ? $term->count : 0; } add_shortcode( ‘category_post_count’, ‘category_post_count’ ); Usage … Read more

Shortcode display outside the div

Use this instead: Concatenate the html then return it. function check_my_login( $atts) { $html=”<form action=”” name=”” method=”post” enctype=”multipart/form-data”>”; $html .= ‘<div class=”form-group”>’; $html .= ‘<label for=”description”>Project Description</label>’; $html .= ‘<textarea name=”p_description” placeholder=”Project Description” class=”form-control”>’; if(isset($_POST[‘p_description’]) && $_POST[‘p_description’] != ”){ $html .= $_POST[‘p_description’]; } $html .= ‘</textarea>’; $html .= ‘</div>’; $html .= ‘<div class=”form-group”>’; $html .= … Read more