Delete empty title_tags, find a h1 heading and echo it

You can’t do if(the_title()) cuz the_title() this code’ll echo a value… Use get_the_title() for a return of the value.

Remove this code too: $newtitle = h1 -> outercontent;

Do this for check if title is empty:

if(empty(get_the_title())){
    // Is empty
} else {
    // is not empty
}

Or you can do only this:

if(!empty(get_the_title())){
    // I'm not empty, write your h1 code and title
}

You can do this too:

$title = !empty(get_the_title()) ? '<h1>' . get_the_title() . '</h1>' : '';
echo $title;