WordPress.org

Ready to get started?Download WordPress

Forums

embedded objects and <!---more--> tag (2 posts)

  1. antr
    Member
    Posted 4 years ago #

    I have several posts with embedded objects (flash games) which load automatically. If I insert them in the first post lines, the page with the posts list will take too much time and memory to load. So, I have to move the embedded object tags after the <!---more--> tag, and insert a screenshot image just before the <!---more--> tag to make the user understand which object he can see in the single post page.
    However, in the single post page, the screenshot just before the embedded object become totally useless.
    I ask if there is a method to make some part of the post (in this case the screenshot image) appear only in the posts list page (the one that write the first lines of each post before the <!---more--> tag) but not in the single post page.
    Otherwise, is there another solution?

  2. Michael Fields
    Themer
    Posted 4 years ago #

    Adding the following function to your themes' functions.php file should do the trick:

    add_filter( 'the_content', 'mfields_trim_teaser' );
    if( !function_exists( 'mfields_trim_teaser' ) ) {
    	function mfields_trim_teaser( $content ) {
    		if ( is_single() && preg_match( '/<span id="more-(.*?)?">/', $content, $matches ) ) {
    			$parts = explode( $matches[0], $content, 2 );
    			if( isset( $parts[1] ) && !empty( $parts[1]	 ) )
    				$content = $parts[1];
    		}
    		return $content;
    	}
    }

Topic Closed

This topic has been closed to new replies.

About this Topic