{"id":5137,"date":"2013-01-30T02:33:41","date_gmt":"2013-01-30T02:33:41","guid":{"rendered":"http:\/\/zerokidz.com\/ideas\/?p=5137"},"modified":"2016-04-24T00:45:50","modified_gmt":"2016-04-24T04:45:50","slug":"how-to-add-a-random-post-button-in-wordpress","status":"publish","type":"post","link":"https:\/\/reactivemusic.net\/?p=5137","title":{"rendered":"How to add a random post button in WordPress"},"content":{"rendered":"<p><cite>by teachyourselfwebsites.com<\/cite><\/p>\n<p>I used this method to add a &#8220;random post&#8221; to this site. I didn&#8217;t create a child theme. So it will break when the theme gets updated.<\/p>\n<p><a href=\"http:\/\/teachyourselfwebsites.com\/create-random-post-button-wordpress-blog\/\">http:\/\/teachyourselfwebsites.com\/create-random-post-button-wordpress-blog\/<\/a><\/p>\n<p><iframe loading=\"lazy\" title=\"Create A Random Post Button For Your WordPress Blog\" width=\"525\" height=\"295\" src=\"https:\/\/www.youtube.com\/embed\/fOUwQW5agJ4?feature=oembed\" frameborder=\"0\" allow=\"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share\" referrerpolicy=\"strict-origin-when-cross-origin\" allowfullscreen><\/iframe><\/p>\n<p>4\/24\/2016 note:<\/p>\n<p>Here are some details. You need to create a new file inside the theme called page-random.php based on the original page.php.<\/p>\n<p>the added code looks like this and goes right before get_header():<\/p>\n<p>&nbsp;<\/p>\n<pre>&lt;?php\r\n\/* Template Name: Random Post *\/\r\n\r\n$randomPost = get_posts(array(\r\n &#039;numberposts&#039; =&gt; 1,\r\n &#039;orderby&#039; =&gt; &#039;rand&#039;\r\n));\r\n \r\nforeach ($randomPost as $post) {\r\n wp_redirect(get_permalink($post-&gt;ID));\r\n exit();\r\n}<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>by teachyourselfwebsites.com I used this method to add a &#8220;random post&#8221; to this site. I didn&#8217;t create a child theme. So it will break when the theme gets updated. http:\/\/teachyourselfwebsites.com\/create-random-post-button-wordpress-blog\/ 4\/24\/2016 note: Here are some details. You need to create a new file inside the theme called page-random.php based on the original page.php. the added &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/reactivemusic.net\/?p=5137\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;How to add a random post button in WordPress&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_coblocks_attr":"","_coblocks_dimensions":"","_coblocks_responsive_height":"","_coblocks_accordion_ie_support":"","footnotes":""},"categories":[142],"tags":[191,90,190,47],"class_list":["post-5137","post","type-post","status-publish","format-standard","hentry","category-ideas","tag-favorites","tag-how-to","tag-portfolio","tag-wordpress"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.4 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>How to add a random post button in Wordpress - reactive music<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/reactivemusic.net\/?p=5137\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How to add a random post button in Wordpress - reactive music\" \/>\n<meta property=\"og:description\" content=\"by teachyourselfwebsites.com I used this method to add a &#8220;random post&#8221; to this site. I didn&#8217;t create a child theme. So it will break when the theme gets updated. http:\/\/teachyourselfwebsites.com\/create-random-post-button-wordpress-blog\/ 4\/24\/2016 note: Here are some details. You need to create a new file inside the theme called page-random.php based on the original page.php. the added &hellip; Continue reading &quot;How to add a random post button in WordPress&quot;\" \/>\n<meta property=\"og:url\" content=\"https:\/\/reactivemusic.net\/?p=5137\" \/>\n<meta property=\"og:site_name\" content=\"reactive music\" \/>\n<meta property=\"article:published_time\" content=\"2013-01-30T02:33:41+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2016-04-24T04:45:50+00:00\" \/>\n<meta name=\"author\" content=\"admin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"admin\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"1 minute\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/reactivemusic.net\\\/?p=5137#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/reactivemusic.net\\\/?p=5137\"},\"author\":{\"name\":\"admin\",\"@id\":\"https:\\\/\\\/reactivemusic.net\\\/#\\\/schema\\\/person\\\/b1e4349f476bb0f42552ff4f61a575d5\"},\"headline\":\"How to add a random post button in WordPress\",\"datePublished\":\"2013-01-30T02:33:41+00:00\",\"dateModified\":\"2016-04-24T04:45:50+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/reactivemusic.net\\\/?p=5137\"},\"wordCount\":86,\"keywords\":[\"favorites\",\"how to\",\"portfolio\",\"wordpress\"],\"articleSection\":[\"ideas\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/reactivemusic.net\\\/?p=5137\",\"url\":\"https:\\\/\\\/reactivemusic.net\\\/?p=5137\",\"name\":\"How to add a random post button in Wordpress - reactive music\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/reactivemusic.net\\\/#website\"},\"datePublished\":\"2013-01-30T02:33:41+00:00\",\"dateModified\":\"2016-04-24T04:45:50+00:00\",\"author\":{\"@id\":\"https:\\\/\\\/reactivemusic.net\\\/#\\\/schema\\\/person\\\/b1e4349f476bb0f42552ff4f61a575d5\"},\"breadcrumb\":{\"@id\":\"https:\\\/\\\/reactivemusic.net\\\/?p=5137#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/reactivemusic.net\\\/?p=5137\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/reactivemusic.net\\\/?p=5137#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/reactivemusic.net\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"How to add a random post button in WordPress\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/reactivemusic.net\\\/#website\",\"url\":\"https:\\\/\\\/reactivemusic.net\\\/\",\"name\":\"reactive music\",\"description\":\"\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/reactivemusic.net\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/reactivemusic.net\\\/#\\\/schema\\\/person\\\/b1e4349f476bb0f42552ff4f61a575d5\",\"name\":\"admin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/2fdaf5f4af2a11b30054b546d0f5f24f4718bb82189f397b3a028aba400f16bb?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/2fdaf5f4af2a11b30054b546d0f5f24f4718bb82189f397b3a028aba400f16bb?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/2fdaf5f4af2a11b30054b546d0f5f24f4718bb82189f397b3a028aba400f16bb?s=96&d=mm&r=g\",\"caption\":\"admin\"},\"url\":\"https:\\\/\\\/reactivemusic.net\\\/?author=1\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"How to add a random post button in Wordpress - reactive music","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/reactivemusic.net\/?p=5137","og_locale":"en_US","og_type":"article","og_title":"How to add a random post button in Wordpress - reactive music","og_description":"by teachyourselfwebsites.com I used this method to add a &#8220;random post&#8221; to this site. I didn&#8217;t create a child theme. So it will break when the theme gets updated. http:\/\/teachyourselfwebsites.com\/create-random-post-button-wordpress-blog\/ 4\/24\/2016 note: Here are some details. You need to create a new file inside the theme called page-random.php based on the original page.php. the added &hellip; Continue reading \"How to add a random post button in WordPress\"","og_url":"https:\/\/reactivemusic.net\/?p=5137","og_site_name":"reactive music","article_published_time":"2013-01-30T02:33:41+00:00","article_modified_time":"2016-04-24T04:45:50+00:00","author":"admin","twitter_card":"summary_large_image","twitter_misc":{"Written by":"admin","Est. reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/reactivemusic.net\/?p=5137#article","isPartOf":{"@id":"https:\/\/reactivemusic.net\/?p=5137"},"author":{"name":"admin","@id":"https:\/\/reactivemusic.net\/#\/schema\/person\/b1e4349f476bb0f42552ff4f61a575d5"},"headline":"How to add a random post button in WordPress","datePublished":"2013-01-30T02:33:41+00:00","dateModified":"2016-04-24T04:45:50+00:00","mainEntityOfPage":{"@id":"https:\/\/reactivemusic.net\/?p=5137"},"wordCount":86,"keywords":["favorites","how to","portfolio","wordpress"],"articleSection":["ideas"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/reactivemusic.net\/?p=5137","url":"https:\/\/reactivemusic.net\/?p=5137","name":"How to add a random post button in Wordpress - reactive music","isPartOf":{"@id":"https:\/\/reactivemusic.net\/#website"},"datePublished":"2013-01-30T02:33:41+00:00","dateModified":"2016-04-24T04:45:50+00:00","author":{"@id":"https:\/\/reactivemusic.net\/#\/schema\/person\/b1e4349f476bb0f42552ff4f61a575d5"},"breadcrumb":{"@id":"https:\/\/reactivemusic.net\/?p=5137#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/reactivemusic.net\/?p=5137"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/reactivemusic.net\/?p=5137#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/reactivemusic.net\/"},{"@type":"ListItem","position":2,"name":"How to add a random post button in WordPress"}]},{"@type":"WebSite","@id":"https:\/\/reactivemusic.net\/#website","url":"https:\/\/reactivemusic.net\/","name":"reactive music","description":"","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/reactivemusic.net\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/reactivemusic.net\/#\/schema\/person\/b1e4349f476bb0f42552ff4f61a575d5","name":"admin","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/2fdaf5f4af2a11b30054b546d0f5f24f4718bb82189f397b3a028aba400f16bb?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/2fdaf5f4af2a11b30054b546d0f5f24f4718bb82189f397b3a028aba400f16bb?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/2fdaf5f4af2a11b30054b546d0f5f24f4718bb82189f397b3a028aba400f16bb?s=96&d=mm&r=g","caption":"admin"},"url":"https:\/\/reactivemusic.net\/?author=1"}]}},"_links":{"self":[{"href":"https:\/\/reactivemusic.net\/index.php?rest_route=\/wp\/v2\/posts\/5137","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/reactivemusic.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/reactivemusic.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/reactivemusic.net\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/reactivemusic.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=5137"}],"version-history":[{"count":10,"href":"https:\/\/reactivemusic.net\/index.php?rest_route=\/wp\/v2\/posts\/5137\/revisions"}],"predecessor-version":[{"id":19548,"href":"https:\/\/reactivemusic.net\/index.php?rest_route=\/wp\/v2\/posts\/5137\/revisions\/19548"}],"wp:attachment":[{"href":"https:\/\/reactivemusic.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=5137"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/reactivemusic.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=5137"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/reactivemusic.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=5137"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}