Help with conditional tags and if-else code

Hello
I am trying to make the main title on single posts say 'News and insight' instead of the post title (as the post title appears in the content area anyway).

I know that the bit of code I need to change is in the /Avada/framework/custom_functions.php file around line 930.

Original code is:

<div class="page-title">
<div class="page-title-wrapper">
<div class="page-title-captions">
<?php if( $title ): ?>
<h1<?php if( ! $smof_data['disable_date_rich_snippet_pages'] ) { echo ' class="entry-title"'; } ?>><?php echo $title; ?></h1>
<?php if( $subtitle ): ?>
<h3><?php echo $subtitle; ?></h3>
<?php endif; ?>
<?php endif; ?>
<?php
if( $alignment == 'center') {
echo $secondary_content;
}
?>
</div>
<?php
if( $alignment != 'center') {
echo $secondary_content;
}
?>
</div>
</div>

I'm not familiar with php coding but I think I need to change it to something like:

<div class="page-title">
<div class="page-title-wrapper">
<div class="page-title-captions">
<?php if ( is_single() ): ?>
<h1>News and insight</h1>
<?php else: ?>
<?php if( $title ): ?>
<h1<?php if( ! $smof_data['disable_date_rich_snippet_pages'] ) { echo ' class="entry-title"'; } ?>><?php echo $title; ?></h1>
<?php if( $subtitle ): ?>
<h3><?php echo $subtitle; ?></h3>
<?php endif; ?>
<?php endif; ?>
<?php
if( $alignment == 'center') {
echo $secondary_content;
}
?>
</div>
<?php
if( $alignment != 'center') {
echo $secondary_content;
}
?>
</div>
</div>

but this doesn't work.

Any advice would be very welcome.
many thanks
Mariette

  • Michael Bissett

    Hey @Mariette! :slight_smile:

    I haven't used the Avada theme myself, but this may do the trick for you:

    <div class="page-title">
    <div class="page-title-wrapper">
    <div class="page-title-captions">
    <?php if( $title ): ?>
    <h1<?php if( ! $smof_data['disable_date_rich_snippet_pages'] ) { echo ' class="entry-title"'; } ?>><?php if ( is_single ) { echo '<h1>News and insight</h1>'; } else { echo $title; } ?></h1>
    <?php if( $subtitle ): ?>
    <h3><?php echo $subtitle; ?></h3>
    <?php endif; ?>
    <?php endif; ?>
    <?php
    if( $alignment == 'center') {
    echo $secondary_content;
    }
    ?>
    </div>
    <?php
    if( $alignment != 'center') {
    echo $secondary_content;
    }
    ?>
    </div>
    </div>

    Could you give that a try please? :slight_smile:

    Kind Regards,
    Michael

  • Mariette

    Hi Michael
    Thank you very much for looking into my problem for me. I have pasted in that code but unfortunately I am now seeing 'News and insight' on all pages and posts. Looking at the code in Firebug it looks like this:

    <div class="page-title">
    <div class="page-title-wrapper">
    <div class="page-title-captions">
    <h1 class="entry-title"></h1>
    <h1>News and insight</h1>
    </div>
    </div>
    </div>

    (two h1s, the entry-title class one being empty).

    best wishes
    Mariette

  • Adam Czajczyk

    Hello Mariette,

    I hope you're well today!

    I think you took a right direction with your code, except there might be a small mistake - every if... else conditional block should have an ending and it seems like your code lacks one. Anyway, I'm not quite able to test it myself because I've got no access to Avada, but could you please try this one?

    <div class="page-title">
    	<div class="page-title-wrapper">
    		<div class="page-title-captions">
    		<?php if ( is_single() ): ?>
    			<h1>News and insight</h1>
    		<?php else: ?>
    			<?php if( $title ): ?>
    			<h1<?php if( ! $smof_data['disable_date_rich_snippet_pages'] ) {
    				echo ' class="entry-title"';
    				} ?>><?php echo $title; ?></h1>
    				<?php if( $subtitle ): ?>
    					<h3><?php echo $subtitle; ?></h3>
    				<?php endif; ?>
    			<?php endif; ?>
    		<?php endif; ?>
    <?php
    if( $alignment == 'center') {
    echo $secondary_content;
    }
    ?>
    </div>
    <?php
    if( $alignment != 'center') {
    echo $secondary_content;
    }
    ?>
    </div>
    </div>

    Let me know please what's the result.

    Cheers,
    Adam

  • Mariette

    Hello again

    I'm really asking a lot here but my problem regarding conditional tags etc to replace the default page title on single posts has re-appeared because Avada have updated their theme and rewritten most of the code, including this element. So now the code relating to the page title has moved to a different file and it looks slightly different (for example, there don't seem to be any <?php endif; ?> lines). This is how the code looks now:

    // Render the page title bar
    echo sprintf( '<div class="fusion-page-title-bar fusion-page-title-bar-%s fusion-page-title-bar-%s">', $content_type, $alignment );
    echo '<div class="fusion-page-title-row">';
    echo '<div class="fusion-page-title-wrapper">';
    echo '<div class="fusion-page-title-captions">';
    if( $title ) {
    // Add entry-title for rich snippets
    $entry_title_class = '';
    if ( ! $smof_data['disable_date_rich_snippet_pages'] ) {
    $entry_title_class = ' class="entry-title"';
    }
    echo sprintf( '<h1%s>%s</h1>', $entry_title_class, $title );

    if ( $subtitle ) {
    echo sprintf( '<h3>%s</h3>', $subtitle );
    }
    }

    // Render secondary content on center layout
    if ( $alignment == 'center') {
    if ( fusion_get_option( 'page_title_bar_bs', 'page_title_breadcrumbs_search_bar', $post_id ) != 'none' ) {
    echo '<div class="fusion-page-title-secondary">';
    echo $secondary_content;
    echo '</div>';
    }
    }

    echo '</div>';

    Would anyone be able to help me with adding a conditional tag, something like

    <?php if ( is_single() ): ?>
    <h1>News and insight</h1>
    <?php else: ?>

    to the above code.

    many thanks
    Mariette

  • Predrag Dubajic

    Hey @Mariette,

    Hope you're doing well today :slight_smile:

    Try using the code below and see if that works for you:

    // Render the page title bar
    echo sprintf( '<div class="fusion-page-title-bar fusion-page-title-bar-%s fusion-page-title-bar-%s">', $content_type, $alignment );
    echo '<div class="fusion-page-title-row">';
    echo '<div class="fusion-page-title-wrapper">';
    echo '<div class="fusion-page-title-captions">';
    
    if ( is_single() ) {
    	echo '<h1>News and insight</h1>';
    } else {
    	if( $title ) {
    		// Add entry-title for rich snippets
    		$entry_title_class = '';
    		if ( ! $smof_data['disable_date_rich_snippet_pages'] ) {
    			$entry_title_class = ' class="entry-title"';
    		}
    
    		echo sprintf( '<h1%s>%s</h1>', $entry_title_class, $title );
    
    		if ( $subtitle ) {
    			echo sprintf( '<h3>%s</h3>', $subtitle );
    		}
    	}
    }
    // Render secondary content on center layout
    if ( $alignment == 'center') {
    	if ( fusion_get_option( 'page_title_bar_bs', 'page_title_breadcrumbs_search_bar', $post_id ) != 'none' ) {
    		echo '<div class="fusion-page-title-secondary">';
    		echo $secondary_content;
    		echo '</div>';
    	}
    }
    
    echo '</div>';

    Little more info here, you can either use { } or endif for conditions.
    For example this code:

    if ( is_single() ):
    	//Do something
    else:
    	//Do something else
    endif;

    Will do same this as this one:

    if ( is_single() ) {
    	//Do something
    } else {
    	//Do something else
    }

    Hope this helps :slight_smile:

    Best regards,
    Predrag

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.