WordPress adds custom content after a certain number of words

WordPress one five hundred and twenty-one Reading mode

Using the following code, you can easily add custom content after a certain number of words in a WordPress article.

 WordPress adds custom content after a certain number of words - Picture 1

WordPress adds custom content after a certain number of words

Add code to the current topic function template functions.php:

 add_filter('the_content', 'zm_insert_content_after_chars_words'); function zm_insert_content_after_chars_words($content) { //Perform this operation when more than 1000 characters $enable_length = 1500; //Insert after the first</p>after 500 characters $after_character = 1500; if ( is_single() && strlen( $content ) > $enable_length ) { $before_content = substr( $content, 0, $after_character ); $after_content = substr($content, $after_character ); $after_content = explode( '</p>', $after_content ); $text='Text content'; array_splice( $after_content, 1, 0, $text ); $after_content = implode( '</p>', $after_content ); return $before_content . $ after_content; } else { return $content; } }

Related articles

WordPress在一定字数之后添加自定义内容-图片2
If you want to add custom content after the paragraph of a WordPress article, such as adding an advertisement after the second paragraph of the article, you can try the following code://At the end of the second paragraph of the article
five hundred and twenty-eight six

Most of the articles on this site are original and used for personal learning records, which may be helpful to you, for reference only!

 weinxin
My Wechat
Copyright Notice
Please indicate the source and link of the original article reprinted on this site. Thank you for your cooperation!
five hundred and ninety-eight million eight hundred and forty-five thousand and six
 
 Robin
five hundred and ninety-eight million eight hundred and forty-five thousand and six
    •  simple life
      simple life four

       :evil: One trick a day! Good, learned!

     anonymous

    Comment

    Anonymous netizens
     :?:  :razz:  :sad:  :evil:  :!:  :smile:  :oops:  :grin:  :eek:  :shock:  :???:  :cool:  :lol:  :mad:  :twisted:  :roll:  :wink:  :idea:  :arrow:  :neutral:  :cry:  :mrgreen:

    Drag the slider to complete validation