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

How can I make all gallery images to open in a new window?

(Update 04.05.2012: Include captions) Let’s start with a solution … There is no filter especially for gallery image links. There is also no filter for the gallery shortcode output. So we have to fake one: add_action( ‘after_setup_theme’, ‘wpse_50911_replace_img_shortcodes’ ); /** * Replace the default shortcode handlers. * * @return void */ function wpse_50911_replace_img_shortcodes() { remove_shortcode( … Read more

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