Wordpress single post content class customization with if-else function
The third &lt;div&gt; appears to be the same in all three cases, so that can be abstracted out of the cases.
The outermost &lt;div&gt; appears to have class pt-4 applied only if is_page_template( 'landingpage.php' ) returns a value that evaluates to FALSE and is_single() returns a value that evaluates to TRUE.
And the first nested (i.e. second) &lt;div&gt; has class container-fluid if either of those functions return a value that evaluates to TRUE.
This logic could be rewritten as below. I know it strays away from the familiar wordpress style of using the Alternative syntax for control structures and uses the shortcut syntax (i.e. &lt;?=) of echo but it does add some separation of the logic from the markup
&lt;?php
// default class names
$contentClass = 'site-content';
$containerClass = 'container-fluid';
if (!is_page_template( 'landingpage.php' )) {
    if (is_single()) {
        $contentClass .= ' pt-4';
    }
    else {
        $containerClass = 'container';
    }
}
?&gt;
    &lt;div id=&quot;content&quot; class=&quot;&lt;?= $contentClass; ?&gt;&quot;&gt;
        &lt;div class=&quot;&lt;?= $containerClass; ?&gt;&quot;&gt;
            &lt;div class=&quot;row&quot;&gt;

It could be simplified using ternary operators but some may argue that would detract from readability.

Is this shorter?
yes, only by two lines

is this more elegant?
Well, that is subjective. The code above should be simpler to read. Consider the scenario where the code is updated by multiple people, including programmers and designers. The programmers can have designers update the markup without affecting the business logic. For more on this topic, refer to Mixing PHP and HTML.