Problem with running javascript in a shortcode
jQuery is running in compatibility mode in WP. Instead of … $(document).ready(function() {} … use … jQuery(document).ready(function($) {}
jQuery is running in compatibility mode in WP. Instead of … $(document).ready(function() {} … use … jQuery(document).ready(function($) {}
You didn’t add the shortcode via the shortcode API. WordPress only recognizes shortcodes if they are added with: add_shortcode( ‘yourshortcode’, ‘yourshortcodefunc’ ); I personally would not use preg_replace for this because it is more of a hit and miss. You should follow the official guidelines off the WordPress Codex. Recommended code structure for shortcodes is: … Read more
hook the_posts and inspect each post to see if your shortcode is present, you can use wp_enqueue_style at that point if it is. maybe a bit of regex to check for the presence of the shortcode is the way to go, unfortunately i’m not very good with regex! function wpse27772_has_shortcode($posts) { if ( empty($posts) ) … Read more
add_shortcode( ‘hidetext’, ‘my_hidetext_shortcode’ ); function my_hidetext_shortcode( $atts, $content=”” ) { if( is_single() ) return $content; else return; } Docs: add_shortcode(), is_single() Solution is untested.
<?php echo do_shortcode(“[apply]<a href=”” . site_url() . “/quick-quote”>Quick Quote</a>[/apply]”); ?>
There’s no need to use regex for this. WordPress has a Shortcode API to do this work for you. That codex page includes one of my favorite codex code snippets: function bartag_func( $atts ) { extract( shortcode_atts( array( ‘foo’ => ‘something’, ‘bar’ => ‘something else’, ), $atts ) ); … Right at the start of … Read more
The reason echo do_shortcode(“[/expand]”); is not working is because [/expand] is not a valid shortcode on it’s own. The combination of [expand] and [/expand] is valid so echo do_shortcode(“[expand] some content [/expand]”); should work as intended. If you want to use this way of seting things up <?php echo do_shortcode(“[expand]”); ?> content <?php echo do_shortcode(“[/expand]”); … Read more
By the time your shortcode runs on the the_content hook (usually) the main query has executed, the pre_get_posts hook has fired for the main query, and the template_redirect hook has fired. You won’t be able to hook to template_redirect or alter the main query (if that is what you need) without somehow getting your shortcode … Read more
There is no difference. This is a complete shortcode plugin: /* Plugin Name: blogname */ add_shortcode( ‘blogname’, ‘get_bloginfo’ ); Usually, you should never register shortcodes in a theme, because the content will be useless after a a theme switch. So, a plugin is the better option.
Per the Codex, is_author() checks to see if you’re on an Author Archive page (ie, a page listing all the posts/pages/etc that a given user has authored). If you’re on any other type of page, is_author() will return false. What you’re looking for sounds more along these lines: if ( in_the_loop() ) { get_currentuserinfo(); print … Read more