Where to call add_shortcode function in WordPress Plugin Boilerplate?

If you look at the /includes/class-plugin-loader.php you will see the public function add_shortcode( $tag, $component, $callback, $priority = 10, $accepted_args = 2 ) { $this->shortcodes = $this->add( $this->shortcodes, $tag, $component, $callback, $priority, $accepted_args ); } That builds a list of shortcodes to be registered with WordPress. You use that via /includes/class-plugin.php within this function: /** … Read more

stop shortcode stripping in category and archive pages

Shortcodes are stripped from the excerpt before filters are applied. Try something more like this: function tsc_execute_shortcodes_in_excerpts( $text, $raw_text ){ if(empty($raw_text)){ $text = get_the_content(”); $text = apply_filters(‘the_content’, $text); $text = str_replace(‘]]>’, ‘]]>’, $text); $text = strip_tags($text); $excerpt_length = apply_filters(‘excerpt_length’, 55); $excerpt_more = apply_filters(‘excerpt_more’, ‘ ‘ . ‘[…]’); $words = preg_split(“/[\n\r\t ]+/”, $text, $excerpt_length + 1, … Read more

Shortcode content filter?

you can use regex to find your the src and use that to append your “files/myimagescript?” to it: function append_myimagescript($attr, $content){ $pattern = ‘/src=”https://wordpress.stackexchange.com/questions/11618/([^”]*)”/i’; $replacement=”files/myimagescript?${1}”; return preg_replace($pattern, $replacement, $content); }

Any Short code Availble for Get Post List With Thumbnail Plugin?

here is a quick crack at making it a shortcode paste this code in your theme’s functions.php file: add_shortcode(‘gplt’,’getPostListThumbs_shortcode’); function getPostListThumbs_shortcode($atts, $content = null){ extract(shortcode_atts(array( ‘orient’ => ‘v’, ‘imgo’ => false, ‘ttgo’ => false, ‘dtgo’ => false, ‘dtfrm’ => 1, ‘categ’ => ”, ‘postnr’ => 20, ‘linn’ => 3, ‘tbwid’ => 40, ‘tbhig’ => 40 … Read more

Custom CSS for plugin form

you can check with the_posts hook if your shortcode exists and only enqueue the style if so : function check_for_shortcode($posts) { if ( empty($posts) ) return $posts; $found = false; foreach ($posts as $post) { if ( stripos($post->post_content, ‘[CHANGE_TO_YOUR_SHORT_CODE’) ) $found = true; break; } if ($found){ $url = get_bloginfo( ‘template_directory’ ); wp_enqueue_style( ‘my_login_Stylesheet’,$url.’/my_login_Stylesheet.css’ ); … Read more

get_shortcode_regex() only matches first shortcode

From PHP docs (emphasis mine): preg_match() returns the number of times pattern matches. That will be either 0 times (no match) or 1 time because preg_match() will stop searching after the first match. preg_match_all() on the contrary will continue until it reaches the end of subject.

Get the content inside shortcode and apply external function to it?

The following adds the shortcode [my_t_shortcode], which accepts an attribute ‘lang’, and applys the above mentioned function to the content. //Add shortcodes add_shortcode( ‘my_t_shortcode’, ‘wpse41477_shortcode_handler’ ); //It’s good practise to make sure your functions are prefixed by something unique function wpse41477_shortcode_handler( $atts, $content = null ) { //This will extract ‘lang’ attribute as $lang. You … Read more