{"id":121945,"date":"2013-09-23T11:30:45","date_gmt":"2013-09-23T15:30:45","guid":{"rendered":"http:\/\/wpmu.org\/?p=121945"},"modified":"2013-09-23T07:40:52","modified_gmt":"2013-09-23T11:40:52","slug":"add-filler-text-to-blank-wordpress-pages","status":"publish","type":"post","link":"https:\/\/wpmudev.com\/blog\/add-filler-text-to-blank-wordpress-pages\/","title":{"rendered":"Automatically Add Filler Text to Blank WordPress Pages and Posts"},"content":{"rendered":"<p>When you&#8217;re setting up a new WordPress site it can be somewhat disheartening to load up a newly installed theme in your browser only to find it empty and limp, devoid of your wonderful words.<\/p>\n<p>But it doesn&#8217;t have to be that way. Adding filler text is a handy way to fill out your site while you&#8217;re customizing your theme. If you&#8217;ve ever done this manually, you know that copying and pasting text into new pages and posts can be time consuming and a tad boring.<\/p>\n<p>To make the process easier, this awesome code snippet adds a few paragraphs of lorem ipsum placeholder text to any blank page or post when you hist &#8220;Publish.&#8221;<\/p>\n<div class=\"image-grid cgrid-row\">\n<div class=\"cgrid-col cgrid-col-span-full\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-ratio-large wp-image-121952\" src=\"https:\/\/wpmudev.com\/blog\/wp-content\/uploads\/2013\/09\/lorem-ipsum-700x248.jpg\" alt=\"Lorem Ipsum\" width=\"700\" height=\"248\" \/><\/div>\n<\/div>\n<p>The text is retrieved from <a title=\"Lipsum\" href=\"http:\/\/www.lipsum.com\" rel=\"noopener\" target=\"_blank\">www.lipsum.com<\/a> and is cached site-wide for one hour using the set_transient and get_transient functions.<\/p>\n<p>That hour gives you enough time to replace the filler text with your own content \u2013 and also ensures you aren&#8217;t stuck with lorem ipsum on your site if you forget to replace the dummy text.<\/p>\n<p>Simply add this code to your theme&#8217;s functions.php file and you&#8217;re good to go:<\/p>\n<p>{code type=php}add_filter (&#8216;the_content&#8217;, &#8217;emw_custom_filter_the_content&#8217;);<\/p>\n<p>\/**<br \/>\n* Returns Lorem Ipsum text for blank pages<br \/>\n*<br \/>\n* @param string $content &#8211; the page&#8217;s current contents<br \/>\n* @return string<br \/>\n*\/<br \/>\nfunction emw_custom_filter_the_content ($content) {<br \/>\nif ($content == &#8221;) {<br \/>\nif ($c = get_transient (&#8216;lipsum&#8217;))<br \/>\nreturn $c;<br \/>\n$content = wp_remote_get (&#8216;http:\/\/www.lipsum.com\/feed\/json&#8217;);<br \/>\nif (!is_wp_error($content)) {<br \/>\n$content = json_decode (str_replace (&#8220;\\n&#8221;, &#8216;<\/p>\n<p>&#8216;, $content[&#8216;body&#8217;]));<br \/>\n$content = &#8216;<\/p>\n<p>&#8216;.$content-&gt;feed-&gt;lipsum.&#8217;<\/p>\n<p>&#8216;;<br \/>\nset_transient (&#8216;lipsum&#8217;, $content, 3600); \/\/ Cache the text for one hour<br \/>\nreturn $content;<br \/>\n}<br \/>\n} else<br \/>\nreturn $content;<br \/>\n}<\/p>\n<p>If you want to keep the filler text for longer than an hour you can edit the <strong>set_transient<\/strong> expiration value to whatever you want. If you want the filler text on your site for a whole day, replace the 17th line of the code with this:<\/p>\n<p>{code type=php}set_transient (&#8216;lipsum&#8217;, $content, 60*60*12);<\/p>\n<p>Or, if you want to keep the filler text indefinitely (though surely you&#8217;ve got your own sweet words to fill your site with and sing to your readers!), you can set the value to never expire:<\/p>\n<p>{code type=php}set_transient (&#8216;lipsum&#8217;, $content, 0);<\/p>\n<p>Thanks to <a title=\"Automatically add Lorem Ipsum text to blank WordPress pages\" href=\"http:\/\/www.wp-code.com\/wordpress-snippets\/automatically-add-lorem-ipsum-text-to-blank-wordpress-pages\/\" rel=\"noopener\" target=\"_blank\">Mark Barnes<\/a> for this handy snippet!<\/p>\n<p>If you want to add more than just filler text, check out Joe Foley&#8217;s helpful post, <a title=\"Lorem Ipsum: Top 5 WordPress Dummy Content Filler Plugins\" href=\"https:\/\/wpmudev.com\/blog\/lorem-ipsum-top-5-wordpress-dummy-content-filler-text-plugins\/\" target=\"_blank\" rel=\"noopener\">Lorem Ipsum: Top 5 WordPress Dummy Content Filler Plugins<\/a>.<\/p>\n<p><strong>Do you use filler content or even theme demo content when you&#8217;re setting up a new WordPress site? Tell us about it in the comments below.<\/strong><\/p>\n<p>Image credits:\u00a0<a title=\"Flickr bburky\" href=\"http:\/\/www.flickr.com\/photos\/bburky_\/\" rel=\"noopener\" target=\"_blank\">bburky<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>When you&#8217;re setting up a new WordPress site it can be somewhat disheartening to load up a newly installed theme in your browser only to find it empty and limp, devoid of your wonderful words. But it doesn&#8217;t have to be that way. Adding filler text is a handy way to fill out your site [&hellip;]<\/p>\n","protected":false},"author":164650,"featured_media":121952,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"blog_reading_time":"","wds_primary_category":0,"wds_primary_tutorials_categories":0,"footnotes":""},"categories":[263],"tags":[],"tutorials_categories":[],"class_list":["post-121945","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-tutorials"],"_links":{"self":[{"href":"https:\/\/wpmudev.com\/blog\/wp-json\/wp\/v2\/posts\/121945","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/wpmudev.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/wpmudev.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/wpmudev.com\/blog\/wp-json\/wp\/v2\/users\/164650"}],"replies":[{"embeddable":true,"href":"https:\/\/wpmudev.com\/blog\/wp-json\/wp\/v2\/comments?post=121945"}],"version-history":[{"count":2,"href":"https:\/\/wpmudev.com\/blog\/wp-json\/wp\/v2\/posts\/121945\/revisions"}],"predecessor-version":[{"id":215939,"href":"https:\/\/wpmudev.com\/blog\/wp-json\/wp\/v2\/posts\/121945\/revisions\/215939"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/wpmudev.com\/blog\/wp-json\/wp\/v2\/media\/121952"}],"wp:attachment":[{"href":"https:\/\/wpmudev.com\/blog\/wp-json\/wp\/v2\/media?parent=121945"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/wpmudev.com\/blog\/wp-json\/wp\/v2\/categories?post=121945"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/wpmudev.com\/blog\/wp-json\/wp\/v2\/tags?post=121945"},{"taxonomy":"tutorials_categories","embeddable":true,"href":"https:\/\/wpmudev.com\/blog\/wp-json\/wp\/v2\/tutorials_categories?post=121945"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}