• Resolved nubevacia

    (@nubevacia)


    Hi,
    I would like insert 2 custom fields named “titleline” and “titleline2” in a H1 tag inside a conditional sentence.
    I’ve read the Codex information but I’m not sure how to put the custom field there.

    Here is the code I’m using:

    <?php if (is_home() ) { 
    
    			echo '<h1>
    			<span>Text here </span>
    			Second line of text here
    			</h1>' ;} 
    
    	else {
                            echo '<h1><span>Custom Field HERE</span>
                                  Custom field2 HERE</h1>' ;} ?>

    Thank you!

Viewing 4 replies - 1 through 4 (of 4 total)
  • Thread Starter nubevacia

    (@nubevacia)

    I know how to do this to show the content, but I can’t figure how to put it inside the H1 tag

    <?php if (is_home() ) { 
    
    			echo '<h1>
    			<span>Learn the language. Live the culture. </span>
    			Study Abroad with Bridge.
    			<div class="clear">&nbsp;</div>
    			</h1>' ;} 
    
    		else { echo get_post_meta($post->ID, 'titleline1', true); } ?>
    Moderator keesiemeijer

    (@keesiemeijer)

    Try to put in the H1 tag like this example:

    $line1 = get_post_meta($post->ID, 'titleline1', true);
    if($line1 != ''){
    echo '<h1>'.$line1.'</h1>';
    }

    Thread Starter nubevacia

    (@nubevacia)

    Thank you, it worked! I’ve adapted tho this:

    <?php if (is_home() ) { 
    
    		echo '<h1>
    		<span>Text </span>
    		Another Line</h1>' ;} 
    
    else {
    	$line1 = get_post_meta($post->ID, 'titleline1', true);
    	$line2 = get_post_meta($post->ID, 'titleline2', true);
    		if($line1 != ''){
    		echo '<h1><span>'.$line1.'</span>'.$line2.'</h1>';
    			} ;} ?>
    Moderator keesiemeijer

    (@keesiemeijer)

    Well done. You don’t need the semicolon between the brackets.
    change this: } ;} to this }}

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Parsing a custom field inside a conditional sentence’ is closed to new replies.