Getting started with WordPressget_bloginfo()Enqueuing scriptsMaking network requests with HTTP APIEnqueuing Styleshome_url()Custom Post Typestemplate_includeThe Loop (main WordPress loop)AJAXThe $wpdb ObjectActions and Filterswp_get_current_user()Add/remove contact info for users with user_contactmethods filter hookCreating a custom templateCustomizer Hello WorldCustomizer Basics (Add Panel, Section, Setting, Control)The Admin Bar (aka "The Toolbar")Querying postsAlternating main loop (pre_get_posts filter)ShortcodeCreate a Post Programmaticallyget_template_part()Taxonomiesget_template_part()ShortcodesPost FormatsCustom exerpts with excerpt_length and excerpt_morePlugin developmentSecurity in WordPress - EscapingTemplate hierarchyRemove Version from Wordpress and StylesheetsChild Theme Basicsadd_action()get_template_part()Shortcode with attributeSidebarsSecurity in WordPress - SanitizationinitCreate Template for Custom Post TypeFunction: add_action()Add ShortcodeHow Can I integrate Markdown editor with Advance Custom Field's repeater Add-on.Installation and Configurationwp_get_current_user()WP-CronSecure your installationOptions APIFunction : wp_trim_words()WP_Query() LoopUpdate WordPress ManuallyThemesWP-CLIDebuggingadd_menu_page()add_submenu_page()get_option()get_permalink()get_the_category()the_title()get_the_title()add_editor_style()add_theme_support()WordPress Plugin creationRun WordPress local with XAMPPAdmin Dashboard WidgetsSite MigrationMeta BoxRemove Auto Line Breaks From Content and Excerptget_home_path()Wordpress theme and child-theme developmentREST API

Function : wp_trim_words()

Other topics

Trimming post content

This function shortens the text to a specified number of words and returns the shortened text.

<?php echo wp_trim_words( get_the_content(), 40, '...' ); ?>

In the above example we are passing the post content to the function. It will restrict the length of the content to 40 words and will trim rest of the words.

Syntax:

  • <?php $trimmed_text = wp_trim_words( $text, $num_words = 55, $more = null ); ?>

Parameters:

ParameterDetails
$text(String) (Required) Text that will be shortened or trimmed.
$num_words(Integer) (Required) Number of words to which text will be restricted.
$more(String) (Optional) What to append if $text needs to be trimmed.

Contributors

Topic Id: 7866

Example Ids: 25573

This site is not affiliated with any of the contributors.