Set document title through shortcode plugin

I have a plugin a web hosting company made for us, and I need the current challenge page to show the challenges name as the document page title. Currently it just displays the page name Current Challenges that contains the shortcode to show the challenge.

The challenge system only had a show challenge list function, which I just limited to 1. But now that I am trying to add the title I made a new function to just show latest added challenge that is published. Why isn't this working though?

function display_latest_challenge($args){
    global $post;
    $challenge_default_args = shortcode_atts(array(
    ),$args);
    $challenge_args = array(
            'posts_per_page'   = 1,
            'orderby'          = 'date',
            'order'            = 'DESC',
            'post_type'        = 'scwd_challenge',
            'post_status'      = 'publish'
        );
    $challenge_string = ;
    $challenges = get_posts( $challenge_args ); 
    
    ob_start();
    foreach ( $challenges as $post ) {
        
        add_filter('pre_get_document_title','challenge_page_title');
    
        ?
        div class=chalList
            ?php setup_postdata($post); $img = get_stylesheet_directory_uri().'/assets/images/placeholder.png';?
                div class=chalSingle
                    ?php include get_template_directory() ./template-parts/scwd-challenge/challenge-title.php; ?
                    ?php include get_template_directory() ./template-parts/scwd-challenge/challenge-info.php; ?
                    ?php include get_template_directory() ./template-parts/scwd-challenge/challenge-winner.php; ?
                    ?php include get_template_directory() ./template-parts/scwd-challenge/challenge-sponsor.php; ?
                    ?php include get_template_directory() ./template-parts/scwd-challenge/challenge-prize.php; ?
                    ?php include get_template_directory() ./template-parts/scwd-challenge/challenge-contestant.php; ?
                /div
        /div
        ?php 
        
    }

    $challenge_string = ob_get_clean();
    wp_reset_postdata();

    return $challenge_string;
}

add_shortcode(show_latest_challenge,'display_latest_challenge');

function challenge_page_title($data){
    global $post;
    return $post-post_title;
}

Topic title shortcode php Wordpress

Category Web

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.