• I have posts that are text and some that are embed YT video links. For the video posts I show the_content(). For text posts, I use echo wp_trim_words(get_the_content(), 50, '')
    If I do this with the video posts, it just shows the video link.

    The archive page with both types of posts has the complete text for each post. Is there a way that I can use echo wp_trim_words(get_the_content(), 50, '') on the archive page with out messing up the video post?

    [ redundant link removed ]

    • This topic was modified 2 years, 9 months ago by Jan Dembowski.

    The page I need help with: [log in to see the link]

Viewing 3 replies - 1 through 3 (of 3 total)
  • Thread Starter kevinritt

    (@kevinritt)

    If trying to do something like this:

    function rbtj_excerpt_mod(){
    	if ( is_page('about') && in_category( 10, 11 ) || is_archive(10,11)){
    		
    	the_content();
    
    	} else {
    	 wp_trim_words(get_the_content(), 50, '');
    	}
    };

    where the posts in cat(10,11) are videos(show content) and the others are echo wp_trim_words(get_the_content(), 50, '')

    Thread Starter kevinritt

    (@kevinritt)

    This is getting me almost there:

    function rbtj_excerpt_mod(){
    	if ( is_page('about-rbtj-ca') && in_category( array(27, 28) ) || is_archive(27, 28)){
    
    	the_content();
    
    	} else {
    
    		if ( is_page('about-rbtj-ca') && in_category( array(29, 30) ) || is_archive(29, 30)) {
    		 echo wp_trim_words(get_the_content(), 50, '');
    	}
    }
    };

    Just not taking effect if I have longer posts in the archive.php file

    • This reply was modified 2 years, 9 months ago by kevinritt.
    Moderator bcworkz

    (@bcworkz)

    The trim words function for making excerpts strips out HTML tags so it can get an accurate word count. This messes up video embed tags. The best way to have reliable HTML tags in an excerpt is to create a dedicated excerpt in the “Excerpt” meta box. You may need to enable excerpt box visibility in the editor’s panel preferences (via 3 dot icon at upper right).

    It’s feasible to filter excerpt content to add a script that “sees” specific video links and adds the proper tags back into the excerpt. ‘wp_trim_words’ filter for example. Requires custom coding though, the excerpt box is much easier to use.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Post excerpt and videos’ is closed to new replies.