{"id":268,"date":"2012-11-30T14:25:43","date_gmt":"2012-11-30T14:25:43","guid":{"rendered":"http:\/\/pixert.com\/blog\/?p=268"},"modified":"2014-05-25T12:33:39","modified_gmt":"2014-05-25T12:33:39","slug":"wordpress-limit-post","status":"publish","type":"post","link":"https:\/\/pixert.com\/blog\/wordpress-limit-post\/","title":{"rendered":"WordPress Limit Post"},"content":{"rendered":"<p><a href=\"https:\/\/i0.wp.com\/pixert.com\/blog\/wp-content\/uploads\/2011\/03\/wordpresslogo.png\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" data-attachment-id=\"25\" data-permalink=\"https:\/\/pixert.com\/blog\/how-to-upgrade-wordpress\/wordpresslogo\/\" data-orig-file=\"https:\/\/i0.wp.com\/pixert.com\/blog\/wp-content\/uploads\/2011\/03\/wordpresslogo.png?fit=498%2C113&amp;ssl=1\" data-orig-size=\"498,113\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;}\" data-image-title=\"WordPress &#8211; the logo\" data-image-description=\"\" data-image-caption=\"\" data-medium-file=\"https:\/\/i0.wp.com\/pixert.com\/blog\/wp-content\/uploads\/2011\/03\/wordpresslogo.png?fit=300%2C68&amp;ssl=1\" data-large-file=\"https:\/\/i0.wp.com\/pixert.com\/blog\/wp-content\/uploads\/2011\/03\/wordpresslogo.png?fit=498%2C113&amp;ssl=1\" class=\"alignright size-medium wp-image-25\" title=\"WordPress - the logo\" alt=\"\" src=\"https:\/\/i0.wp.com\/pixert.com\/blog\/wp-content\/uploads\/2011\/03\/wordpresslogo-300x68.png?resize=300%2C68\" width=\"300\" height=\"68\" srcset=\"https:\/\/i0.wp.com\/pixert.com\/blog\/wp-content\/uploads\/2011\/03\/wordpresslogo.png?resize=300%2C68&amp;ssl=1 300w, https:\/\/i0.wp.com\/pixert.com\/blog\/wp-content\/uploads\/2011\/03\/wordpresslogo.png?w=498&amp;ssl=1 498w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a>This function controls the maximum\u00a0amount of characters displayed for an entry on the main page. If the set limit is surpassed, the text on the entry will be chopped\u00a0to that amount of characters, otherwise the content will be showed unchanged.<\/p>\n<p>Add following code to functions.php in your theme folder<\/p>\n<pre class=\"brush: php; title: Code Block; notranslate\" title=\"Code Block\">\r\n\r\nfunction the_content_limit($max_char, $more_link_text = '(more...)', $stripteaser = 0, $more_file = '') {\r\n$content = get_the_content($more_link_text, $stripteaser, $more_file);\r\n\/\/ remove &#x5B;caption] shortcode\r\n$content = preg_replace(&amp;quot;\/\\&#x5B;caption.*\\&#x5B;\\\/caption\\]\/&amp;quot;, '', $content);\r\n\/\/ short codes are applied\r\n\r\n$content = apply_filters('the_content', $content);\r\n$content = str_replace(']]&amp;gt;', ']]&amp;amp;gt;', $content);\r\n$content = strip_tags($content);\r\n\r\nif ((strlen($content)&amp;gt;$max_char) &amp;amp;&amp;amp; ($espacio\u00a0= strpos($content, &amp;quot; &amp;quot;, $max_char ))) {\r\n$content = substr($content, 0, $espacio);\r\n$content = $content;\r\necho &amp;quot;&amp;lt;p&amp;gt;&amp;quot;;\r\necho $content;\r\necho &amp;quot;...&amp;quot;;\r\necho &amp;quot;&amp;lt;\/p&amp;gt;&amp;quot;;\r\n}\r\nelse {\r\necho &amp;quot;&amp;lt;p&amp;gt;&amp;quot;;\r\necho $content;\r\necho &amp;quot;&amp;lt;\/p&amp;gt;&amp;quot;;\r\n}\r\n}\r\n\r\n<\/pre>\n<p>usage :<br \/>\nadd this code <\/p>\n<pre class=\"brush: php; title: Code Block; notranslate\" title=\"Code Block\"> the_content_limit('100');\u00a0 <\/pre>\n<p>inside WordPress loop. This function usually replace<\/p>\n<pre class=\"brush: php; title: Code Block; notranslate\" title=\"Code Block\">\u00a0the_content(); <\/pre>\n<p>credits: this function from Limit Posts plugin \u00a0(the original plugin author site seems down at the moment). I have updated code above \u00a0to remove Image Caption for showing<\/p>\n","protected":false},"excerpt":{"rendered":"<p>This function controls the maximum\u00a0amount of characters displayed for an entry on the main page. If the set limit is surpassed, the text on the entry will be chopped\u00a0to that amount of characters, otherwise the content will be showed unchanged. Add following code to functions.php in your theme folder function the_content_limit($max_char, $more_link_text = &#8216;(more&#8230;)&#8217;, $stripteaser [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[54,5],"tags":[55,6],"class_list":["post-268","post","type-post","status-publish","format-standard","hentry","category-code-snippet","category-wordpress","tag-code-snippet-2","tag-wordpress-2"],"aioseo_notices":[],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/p1pvi1-4k","jetpack-related-posts":[{"id":279,"url":"https:\/\/pixert.com\/blog\/keep-html-tags-wordpress-limit-posts\/","url_meta":{"origin":268,"position":0},"title":"Keep HTML Tags in WordPress Limit Posts &#8211; the_content_limit","author":"Pixel Insert \/ Pixert","date":"January 8, 2013","format":false,"excerpt":"This function, the_content_limit \u00a0controls the maximum\u00a0amount of characters displayed for an entry on the main page on WordPress homepage posts, e.g Featured Posts, Recent Posts However , the_content_limit stripped HTML tags just like the_excerpt. What if we want to keep HTML tags We make modification to the function, the_content_limit which\u2026","rel":"","context":"In &quot;Code Snippet&quot;","block_context":{"text":"Code Snippet","link":"https:\/\/pixert.com\/blog\/category\/code-snippet\/"},"img":{"alt_text":"WordPress - the logo","src":"https:\/\/i0.wp.com\/pixert.com\/blog\/wp-content\/uploads\/2011\/03\/wordpresslogo-300x68.png?resize=350%2C200","width":350,"height":200},"classes":[]},{"id":130,"url":"https:\/\/pixert.com\/blog\/enable-formatting-tags-for-content-limit-in-genesis-featured-posts-widget\/","url_meta":{"origin":268,"position":1},"title":"Enable Formatting Tags for Content Limit in Genesis Featured Posts widget","author":"Pixel Insert \/ Pixert","date":"January 10, 2013","format":false,"excerpt":"Genesis Framework has same function that return the content after trimming and it strips all HTML The following code help you keep or filter some HTML tags when you are using Content Limit in Theme Settings or Widgets (e.g Genesis - Featured Posts widget) Add following to functions.php in the\u2026","rel":"","context":"In &quot;Code Snippet&quot;","block_context":{"text":"Code Snippet","link":"https:\/\/pixert.com\/blog\/category\/code-snippet\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/pixert.com\/blog\/wp-content\/uploads\/2013\/01\/gallerygenesis.jpg?fit=600%2C340&ssl=1&resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/pixert.com\/blog\/wp-content\/uploads\/2013\/01\/gallerygenesis.jpg?fit=600%2C340&ssl=1&resize=350%2C200 1x, https:\/\/i0.wp.com\/pixert.com\/blog\/wp-content\/uploads\/2013\/01\/gallerygenesis.jpg?fit=600%2C340&ssl=1&resize=525%2C300 1.5x"},"classes":[]},{"id":447,"url":"https:\/\/pixert.com\/blog\/wordpress-randomize-posts-category-page\/","url_meta":{"origin":268,"position":2},"title":"WordPress: Randomize posts in a category page","author":"Pixel Insert \/ Pixert","date":"July 19, 2016","format":false,"excerpt":"The following lines of code change the way of displaying posts in a category page from default to date to random order. Please add following lines of code to functions.php [php] add_action( 'pre_get_posts', 'random_category_posts' ); function random_category_posts( $query ) { if ( $query-&gt;is_category() &amp;&amp; $query-&gt;is_main_query() ) { $query-&gt;set( 'orderby', 'rand'\u2026","rel":"","context":"In &quot;Code Snippet&quot;","block_context":{"text":"Code Snippet","link":"https:\/\/pixert.com\/blog\/category\/code-snippet\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":305,"url":"https:\/\/pixert.com\/blog\/wordpress-conditional-tag-to-check-specific-menu\/","url_meta":{"origin":268,"position":3},"title":"WordPress: Conditional tag to check a specific menu","author":"Pixel Insert \/ Pixert","date":"May 22, 2013","format":false,"excerpt":"Following conditional tag usually use in this filter function, wp_nav_menu_items [php]if( $args->theme_location == 'primary' )[\/php] \u00a0 [php]if( $args->theme_location == 'secondary' )[\/php] \u00a0 [php]if( $args->theme_location == 'primary' )[\/php] For an example, I want to add search box to Primary Menu in WPZOOM theme name Videozoom. Conditional tag above make sure the\u2026","rel":"","context":"In &quot;Code Snippet&quot;","block_context":{"text":"Code Snippet","link":"https:\/\/pixert.com\/blog\/category\/code-snippet\/"},"img":{"alt_text":"wordpress-logo-notext-rgb","src":"https:\/\/i0.wp.com\/pixert.com\/blog\/wp-content\/uploads\/2013\/08\/wordpress-logo-notext-rgb.jpg?resize=350%2C200","width":350,"height":200},"classes":[]},{"id":141,"url":"https:\/\/pixert.com\/blog\/fatal-error-out-of-memory-in-wordpress\/","url_meta":{"origin":268,"position":4},"title":"Fatal Error : Out of Memory in WordPress","author":"Pixel Insert \/ Pixert","date":"October 2, 2011","format":false,"excerpt":"WP_MEMORY_LIMIT option allows you to specify the maximum amount of memory that can be consumed by PHP. This setting may be necessary in the event you receive a message such as \"Allowed memory size of xxxxxx bytes exhausted\". This setting increases PHP Memory only for WordPress, not other applications\u00a0WordPress will\u2026","rel":"","context":"In &quot;Code Snippet&quot;","block_context":{"text":"Code Snippet","link":"https:\/\/pixert.com\/blog\/category\/code-snippet\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/pixert.com\/blog\/wp-content\/uploads\/2011\/03\/wordpresslogo-300x68.png?resize=350%2C200","width":350,"height":200},"classes":[]},{"id":416,"url":"https:\/\/pixert.com\/blog\/wordpress-title-empty-on-index-page\/","url_meta":{"origin":268,"position":5},"title":"WordPress Title Empty on Index Page","author":"Pixel Insert \/ Pixert","date":"November 2, 2014","format":false,"excerpt":"Here's description from WordPress Codex about what happen when WordPress title empty when viewing index page\/ homepage If you are using a custom homepage with custom loops and stuff or a custom front-page, you will have an empty wp_title. I recently encountered this problem on a client's site. Homepage\/Index page\u2026","rel":"","context":"In &quot;Code Snippet&quot;","block_context":{"text":"Code Snippet","link":"https:\/\/pixert.com\/blog\/category\/code-snippet\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]}],"jetpack_sharing_enabled":true,"jetpack_likes_enabled":true,"_links":{"self":[{"href":"https:\/\/pixert.com\/blog\/wp-json\/wp\/v2\/posts\/268","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/pixert.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/pixert.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/pixert.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/pixert.com\/blog\/wp-json\/wp\/v2\/comments?post=268"}],"version-history":[{"count":0,"href":"https:\/\/pixert.com\/blog\/wp-json\/wp\/v2\/posts\/268\/revisions"}],"wp:attachment":[{"href":"https:\/\/pixert.com\/blog\/wp-json\/wp\/v2\/media?parent=268"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/pixert.com\/blog\/wp-json\/wp\/v2\/categories?post=268"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/pixert.com\/blog\/wp-json\/wp\/v2\/tags?post=268"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}