{"id":722,"date":"2018-02-08T15:47:07","date_gmt":"2018-02-08T15:47:07","guid":{"rendered":"http:\/\/sls.gmu.edu\/web\/?p=722"},"modified":"2020-02-19T19:27:18","modified_gmt":"2020-02-19T19:27:18","slug":"list-all-sites-using-custom-shortcode","status":"publish","type":"post","link":"https:\/\/sls.gmu.edu\/web\/2018\/02\/08\/list-all-sites-using-custom-shortcode\/","title":{"rendered":"List All Sites Using Custom Shortcode"},"content":{"rendered":"<p>Shortcodes make it easier to customize wordpress pages quickly. WordPress comes with pre-built shortcodes but we&#8217;re going to build one from scratch. You will need to add a function to your child theme&#8217;s functions.php file. This particular code builds an ordered list of all our wordpress sites under our sls.gmu.edu domain using the get_sites() function. This function will work on all WP platforms 4.3 and above.<\/p>\n<p><code><br \/>\n    \/*<br \/>\n    * Author: Matthew<br \/>\n    * This function creates a shortcode usable in all sites using the scalia law theme to create an ordered list of<br \/>\n    all multisites<br \/>\n    *\/<br \/>\n    function scalia_list_sites() {<\/p>\n<p>    $subsites = get_sites(); \/\/creates variable using get_sites<\/p>\n<p>    if ( ! empty ( $subsites ) ) {<\/p>\n<p>        $html = '<\/p>\n<ol class=\"subsites\">'; \/\/sets up class<\/p>\n<p>        foreach( $subsites as $subsite ) {<\/p>\n<p>            $subsite_id = $subsite->blog_id; \/\/finds sites by id<br \/>\n            $subsite_name = get_blog_details( $subsite_id )->blogname; \/\/creates variable for site name<br \/>\n            $subsite_link = get_blog_details( $subsite_id )->siteurl; \/\/creates variable for site url<br \/>\n            $html .= '< li class=\"site-' . $subsite_id . '\">< a href=\"' . $subsite_link . '\">' . $subsite_name . '< \/a >< \/li >'; \/\/builds individual list items<br \/>\n            sort($html);<br \/>\n        }<\/p>\n<p>        $html .= '< \/ol >';<\/p>\n<p>        return $html; \/\/returns the list<\/p>\n<p>    }<\/p>\n<p>}<br \/>\nadd_shortcode('scalia_list', 'scalia_list_sites'); \/\/calls function and sets up [ scalia_list ] custom short code<\/code><\/p>\n<p>This goes in your child-theme&#8217;s functions.php file. <\/p>\n","protected":false},"excerpt":{"rendered":"<p>Shortcodes make it easier to customize wordpress pages quickly. WordPress comes with pre-built shortcodes but we&#8217;re going to build one from scratch. You will need to add a function to your child theme&#8217;s functions.php file. This particular code builds an ordered list of all our wordpress sites under our sls.gmu.edu domain using the get_sites() function. &hellip; <a href=\"https:\/\/sls.gmu.edu\/web\/2018\/02\/08\/list-all-sites-using-custom-shortcode\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;List All Sites Using Custom Shortcode&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"inline_featured_image":false,"footnotes":""},"categories":[4,11],"tags":[34],"class_list":["post-722","post","type-post","status-publish","format-standard","hentry","category-cms","category-web-development","tag-wordpress"],"_links":{"self":[{"href":"https:\/\/sls.gmu.edu\/web\/wp-json\/wp\/v2\/posts\/722","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/sls.gmu.edu\/web\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/sls.gmu.edu\/web\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/sls.gmu.edu\/web\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/sls.gmu.edu\/web\/wp-json\/wp\/v2\/comments?post=722"}],"version-history":[{"count":0,"href":"https:\/\/sls.gmu.edu\/web\/wp-json\/wp\/v2\/posts\/722\/revisions"}],"wp:attachment":[{"href":"https:\/\/sls.gmu.edu\/web\/wp-json\/wp\/v2\/media?parent=722"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/sls.gmu.edu\/web\/wp-json\/wp\/v2\/categories?post=722"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/sls.gmu.edu\/web\/wp-json\/wp\/v2\/tags?post=722"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}