Adding video duration in wordpress

Hello guys,

I don’t really know php but I am always been able to copy/paste it and move stuff around on my wordpress website until now.

This last challenge is beyond my skills though (I am sure it will be trivial for you).

So I have this code snippet to show a video duration

<?php global $post; $video = cbc_get_video_data( $post ); if( $video ) { echo $video->get_human_duration(); } ?>

And I have this code to show a post title

if ($show_title) {
        $title_content .= apply_filters( 'uncode_before_body_title', '' );
        $title_content .= '<div class="post-title-wrapper"><h1 class="post-title">' . get_the_title() . '</h1>';
        $title_content .= uncode_post_info() . '</div>';
        $title_content .= apply_filters( 'uncode_after_body_title', '' );
    }

I want to show the video duration right before the post title and in line with it, so inside the h1 tag. How to do that?

Thanks for any help!

As i already asked on the other forum you postet this to:

Why don’t you at least try yourself? Just present what problems you encountered to show a slight amount of initiative.

Thank you,
I assure you I do not completely lack initiative :),
the problem here is I do not really know php and I am not a developer either, I just know html and css

I did take a look at your suggested documentation https://www.php.net/manual/en/language.operators.string.php

And i tried something like this (which breaks the site), but I don’t really know what I am doing here

$video_duration = '<span class="video-duration">' global $post; $video = cbc_get_video_data( $post ); if( $video ) {echo $video->get_human_duration();}'</span>'

  if ($show_title) {
		$title_content .= apply_filters( 'uncode_before_body_title', '' );
		$title_content .= '<div class="post-title-wrapper"><h1 class="post-title">'$video_duration . get_the_title() . '</h1>';
		$title_content .= uncode_post_info() . '</div>';
		$title_content .= apply_filters( 'uncode_after_body_title', '' );
	}

Thanks

So,
I ended up doing something like this

  <?php
    $duration = '';
    if( function_exists( 'cbc_get_video_data' ) ){
        global $post;
        $video = cbc_get_video_data( $post );
        if( $video ) {
            $duration = $video->get_human_duration();
        }
    }
    $title_content .= '<div class="post-title-wrapper"><h1 class="post-title">' . $duration . get_the_title() . '</h1>';
?>

which does work. My only problem now is I want to wrap the video $duration value inside a span so I can style it in a different way, but when I do this

<?php
$title_content .= '<div class="post-title-wrapper"><h1 class="post-title">' . get_the_title() . '<span class="video-duration">'$duration'</span>' .'</h1>';
   ?>

it breaks the site, any suggestions?

Thanks

as you see from get_the_title() in the same line your variable must be surrounded by dots.

2 Likes

and why concatenate the h1 end tag? clean it up and make it more legible:

'<span class="video-duration">' . $duration . '</span></h1>';
1 Like

Thanks a lot guys, that solves my issue

1 Like
Sponsor our Newsletter | Privacy Policy | Terms of Service