Reusable Dynamic Taxonomy Shortcode

Ok, I figured out the solution and have it working to where I can swap out the attribute for the shortcode with any taxonomy available associated with every post type: function custom_taxonomy_list_shortcode( $atts ) { $atts = shortcode_atts( array( ‘term’ => ‘location’, //Set whatever default taxonomy you like ), $atts ); global $post; $custom_taxonomy = … Read more

Force ‘permanent’ post cache of shortcode results

You’d want to look up transients Here’s a simple example of how you do it. function showPosts (){ $posts = get_transient (“my_rss_transient”); If (!$posts){$posts=getPosts ();} /* do showing off stuff here */ } function getPosts (){ $posts = /* get posts here*/ Set_transient (“my_rss_transient”, $posts, MONTH_IN_SECONDS); return $posts } The transient should be saved for … Read more

How to add HTML to a template only when user is logged out/ not registered

First of all, your shortcode usage code is incorrect, correct code is: echo do_shortcode(‘[loginout_button]’); Now, if you want to echo the login/logout button only when user is not logged in, you can use the function is_user_logged_in(). There are two ways to do this 1). Conditional logic inside your shortcode. add_shortcode(‘loginout_button’,’add_loginout_button’); function add_loginout_button() { if ( … Read more

How to avoid one code multiple times instead do that through some function? Shortcode, but I think shortcode is not used in main theme’s core files?

You can use PHP’s includes like this: include dirname(__FILE__).’/components/authorSocials.php’; but you should remember about providing the data to your component. Since the idea is that you will you use it in different places, not always the default values will be available and will be the right ones, so you should add some more code to … Read more

Function not receiving string from shortcode

It appears like you can not use upper case like that in a shortcode. Instead of videoUrl, use video-url: function get_youtube_thumb_url_func( $atts ) { $atts = shortcode_atts( array( ‘video-url’ => ‘urlHere’, ), $atts, ‘youtube-thumb-url’ ); return $atts[‘video-url’]; } add_shortcode( ‘youtube-thumb-url’, ‘get_youtube_thumb_url_func’ ); And your shortcode: [youtube-thumb-url video-url=”test”] This is the final function that I tested … Read more