{"id":6843,"date":"2016-04-06T08:00:00","date_gmt":"2016-04-06T08:00:00","guid":{"rendered":"https:\/\/www.weixiaoduo.com\/plugins\/2024\/02\/22\/administrative-shortcodes\/"},"modified":"2021-05-12T03:59:00","modified_gmt":"2021-05-12T03:59:00","slug":"administrative-shortcodes","status":"publish","type":"post","link":"https:\/\/www.weixiaoduo.com\/plugins\/administrative-shortcodes\/","title":{"rendered":"Administrative Shortcodes"},"content":{"rendered":"<p>A set of shortcodes for the website administrators.<\/p>\n<h4>if<\/h4>\n<p>Using this shortcode you can limit the display of the text or shortcodes to specific page(s) on your website. You can use all the <a href=\"https:\/\/codex.wordpress.org\/Conditional_Tags\" rel=\"nofollow ugc\">conditional tags<\/a> WordPress provides. Checkout examples below.<\/p>\n<p>Show text only on the homepage:<\/p>\n<pre><code>[if is_front_page] The text [\/if]\n<\/code><\/pre>\n<p>Show text only on the About page of the site:<\/p>\n<pre><code>[if is_page=\"about\"] The text [\/if]\n<\/code><\/pre>\n<p>Show only on the category archive view:<\/p>\n<pre><code>[if is_category] The text [\/if]\n<\/code><\/pre>\n<p>You can add \u201cnot_\u201d before the conditional tag to reverse the logic, example:<br \/>\nShow on all pages of the site except the homepage:<\/p>\n<pre><code>[if not_is_front_page] The text [\/if]\n<\/code><\/pre>\n<p>Using multiple parameters, the content is displayed when either of the conditions are met (\u201cOR\u201d comparison), for example, show text on both category and tag archive pages:<\/p>\n<pre><code>[if is_category is_tag] The text [\/if]\n<\/code><\/pre>\n<p>To set multiple conditions you can nest the shortcode, for example show text only on homepage AND if the user is logged in:<\/p>\n<pre><code>[if is_user_logged_in][if is_front_page] The text [\/if][\/if]\n<\/code><\/pre>\n<p>Show a link to wordpress.org site, only on single post pages and only on mobile devices:<\/p>\n<pre><code>[if wp_is_mobile][if is_single] <a href=\"https:\/\/wordpress.org\/\">WordPress<\/a> [\/if][\/if]\n<\/code><\/pre>\n<h4>switch_to_blog<\/h4>\n<p>Run shortcodes in the context of another website in the network. This shortcode is only available in multisite installations (WP Network). For example, list posts from another blog:<\/p>\n<pre><code>[switch_to_blog id=\"10\"] [list_posts limit=\"10\"] [\/switch_to_blog]\n<\/code><\/pre>\n<h4>iterator<\/h4>\n<p>Display text or shortcodes only if repeated a certain number of times. Requires an \u201cid\u201d parameter which should be unique for that shortcode (can be anything you want).<\/p>\n<pre><code>[iterator id=\"my-ads\" repeat=\"5\"] My ad codes [\/iterator]\n<\/code><\/pre>\n<p>After every 5th call to that shortcode, render the output.<\/p>\n<h4>get_template<\/h4>\n<p>Load a template file into the page. The referenced file is loaded from child theme if it exists, if not from the parent theme. Example, load includes\/slider.php template file from the theme:<\/p>\n<pre><code>[get_template slug=\"includes\/slider\"]\n<\/code><\/pre>\n<h4>scheduler<\/h4>\n<p>Show text or shortcodes only if the specified date has passed. Example, show the text only if it\u2019s after Christmas of 2016:<\/p>\n<pre><code>[scheduler date=\"December 25, 2016\"] Text [\/scheduler]\n<\/code><\/pre>\n<h4>date<\/h4>\n<p>Shows the current date or time in the specified format (https:\/\/codex.wordpress.org\/Formatting_Date_and_Time). Uses Date Format (in Settings > General) by default.<\/p>\n<pre><code>[date format=\"F j, Y\"]\n<\/code><\/pre>\n<h4>loginoutlink<\/h4>\n<p>Display a link to login page if user is not logged-in, or a logout page if they are. Parameters:<\/p>\n<ul>\n<li>login : \u201cLog in\u201d text<\/li>\n<li>logout : \u201cLog out\u201d text<\/li>\n<li>redirect : optional URL to redirect to on login or logout<\/li>\n<\/ul>\n<h4>login_form<\/h4>\n<p>Display the login form.<\/p>\n<h4>custom_field<\/h4>\n<p>Display a custom field from a post. Parameters:<\/p>\n<ul>\n<li>key : name of the custom field to show. This parameter is required.<\/li>\n<li>post_id : the ID of the post to display the custom field from; by default uses the current post in the loop<\/li>\n<li>before : show a text to display before the value of the field<\/li>\n<li>after : show a text after the value of the field<\/li>\n<\/ul>\n<h4>disable<\/h4>\n<p>Wrap any content or shortcode with <code>[disable]<\/code> shortcode to prevent that piece of content from being rendered. Perfect for debugging shortcodes.<\/p>\n<h4>the_id<\/h4>\n<p>Shows the current post ID; useful when you need to debug WP Loops.<\/p>\n<h4>Path shortcodes<\/h4>\n<p>[home_url] : returns the homepage URL<br \/>\n[get_template_directory] : Absolute path to the parent theme directory<br \/>\n[get_template_directory_uri] : URL to the directory of the parent theme<br \/>\n[get_stylesheet_directory] : Absolute path to the directory of the child theme<br \/>\n[get_stylesheet_directory_uri] : URL to the directory of the child theme<\/p>\n<h4>rand shortcodes<\/h4>\n<p>Show a random number between two numbers. Parameters:<br \/>\n* min : minimum value (default 0)<br \/>\n* max : maximum value (default 100)<\/p>\n<h4>get_var<\/h4>\n<p>Retrieve a value from $_GET or $_POST variables.<br \/>\nTo get a URL query string:<\/p>\n<pre><code>[get_var get=\"myvar\"]\n<\/code><\/pre>\n<p>To get a value from POST:<\/p>\n<pre><code>[get_var post=\"myvar\"]\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>A set of shortcodes for the website administrators.<\/p>\n","protected":false},"author":65,"featured_media":229580,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"slim_seo":{"title":"Administrative Shortcodes - \u8587\u6653\u6735\u63d2\u4ef6\u76ee\u5f55","description":"A set of shortcodes for the website administrators."},"footnotes":""},"categories":[1],"tags":[1282,2807,257,345,1613],"class_list":["post-6843","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-uncategorized","tag-code","tag-context","tag-php","tag-shortcode","tag-wpmu"],"_links":{"self":[{"href":"https:\/\/www.weixiaoduo.com\/plugins\/wp-json\/wp\/v2\/posts\/6843","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.weixiaoduo.com\/plugins\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.weixiaoduo.com\/plugins\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.weixiaoduo.com\/plugins\/wp-json\/wp\/v2\/users\/65"}],"replies":[{"embeddable":true,"href":"https:\/\/www.weixiaoduo.com\/plugins\/wp-json\/wp\/v2\/comments?post=6843"}],"version-history":[{"count":0,"href":"https:\/\/www.weixiaoduo.com\/plugins\/wp-json\/wp\/v2\/posts\/6843\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.weixiaoduo.com\/plugins\/wp-json\/wp\/v2\/media\/229580"}],"wp:attachment":[{"href":"https:\/\/www.weixiaoduo.com\/plugins\/wp-json\/wp\/v2\/media?parent=6843"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.weixiaoduo.com\/plugins\/wp-json\/wp\/v2\/categories?post=6843"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.weixiaoduo.com\/plugins\/wp-json\/wp\/v2\/tags?post=6843"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}