• Resolved jonesgaming2105

    (@jonesgaming2105)


    Hello,

    how can i wrap the description of inserted youtube videos automatically inside a separate container? I want to wrap the description because it is a very long text. So from my side it would make sense to wrap that description into a div to create a spoiler to have comments and sharing more visible.

    I saw that the video is already wrapped inside <div class="tube-video-wrap">...</div>. So why not wrap the complete description inside <div class="tube-video-description">...</div> ??

    Kind regards,
    Jones

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

Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Author tubegtld

    (@tubegtld)

    The description is really just text inserted into the post content.

    So, the wrapping of the description is basically controlled by your theme and not the plugin.

    Assuming your theme uses the_content() to display the post body, which it seems it does since the video is showing up, you can filter the content with a priority lower than 10 to wrap it before the video gets embedded.

    This code is tested and working, so you’ll just need to drop it into your child theme’s functions.php or a simple plugin…

    add_filter( 'the_content', 'mytube_prewrap_post_content', 5 );
    
    function mytube_prewrap_post_content( $the_content ){
      
      // make sure single post main query
      if ( ! is_singular( 'post' ) || ! is_main_query() ) return;   
      
      // return the wrapped content
      return '<div class="my-content-wrap">' . $the_content . '</div>';
      
    }

    Please mark as resolved if this solves your issue, and leave a review if you’re digging the plugin.

    • This reply was modified 6 years, 10 months ago by tubegtld.
    Thread Starter jonesgaming2105

    (@jonesgaming2105)

    Thank you for the quick reply!

    That helped a lot. I changed the string returned by the function to trigger a shortcode from Shortcodes Ultimate Plugin. Works perfect ??

    function mytube_prewrap_post_content( $the_content ){
    
    	// make sure single post main query
    	if ( ! is_singular( 'post' ) || ! is_main_query() ) return;
    
    	// return the wrapped content
    	$customContent = <<<EOD
    	[su_expand more_text="Mehr anzeigen" less_text="Beschreibung ausblenden"
    	height="140" text_color="#888888" link_color="#a86400" link_style="underlined"
    	more_icon="icon: eye" less_icon="icon: eye-slash" class="collapse"]
    	$the_content
    	[/su_expand]
    EOD;
    
    	return $customContent;
    }
    Plugin Author tubegtld

    (@tubegtld)

    There might be some collateral damage caused by conditional logic… no content on the homepage loop.

    If so, try this instead…

    if ( ! ( is_singular( 'post' ) && is_main_query() ) ) return;

    Thread Starter jonesgaming2105

    (@jonesgaming2105)

    It looks like the Oria Template breaks when nothing gets returned. So i changed the code to always return $the_content. Otherwise the content is missing. I also added Hashtag replacement. So Hashtags from YouTube will link to search results from my page ??

    add_filter( 'the_content', 'mytube_prewrap_post_content', 5 );
    
    function mytube_prewrap_post_content( $the_content ){
    
    	$the_content = preg_replace("/#([A-Za-z0-9\/\.]*)/", "<a href=\"https://jones-gaming.de/tag/$1\">#$1</a>", $the_content);
    
    // make sure single post main query
    	if ( ! ( is_singular( 'post' ) && is_main_query() ) ) return $the_content;
    
    // return the wrapped content
    	$customContent = <<<EOD
    [su_expand more_text="Mehr anzeigen" less_text="ausblenden"
    height="140" text_color="#888888" link_color="#a86400" link_style="underlined"
    more_icon="icon: eye" less_icon="icon: eye-slash" class="collapse"]
    $the_content
    [/su_expand]
    EOD;
    
    	return $customContent;
    }
    Plugin Author tubegtld

    (@tubegtld)

    Glad you were able to figure it out.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Wrap description from YT Videos inside a div?’ is closed to new replies.