Support » Plugin: Greg's High Performance SEO » [Plugin: Greg's High Performance SEO] Secondary title repeats main

  • Resolved drumelt

    (@drumelt)


    I want the secondary title in h2 tags if it has been specified, or nothing if it has not been specified. I have put this code into my loop-single.php:

    <?php $title2='';
    if (function_exists('ghpseo_output')) { $title2=ghpseo_output('secondary_title',false); /*echo off */
    if($title2 != '') echo '<h2 class="entry-title2">' . $title2 . '</h2>';} ?>

    [Please post code snippets between backticks or use the code button.]

    The code produces a specified secondary title, but when no secondary has been specified, it still puts out the main title between the h2 tags.

Viewing 3 replies - 1 through 3 (of 3 total)
  • Just to expand on this for others, this is what the code would look like when used in “The Loop”:

    if (function_exists('ghpseo_output'))
    {
    	$title = ghpseo_output('secondary_title', false);
    
    	if ($title == '')
    	{
    		$title = get_the_title( get_the_ID() );
    	}
    
    	echo $title;
    }
    else
    {
    	the_title();
    }
    Plugin Contributor gregmulhauser

    (@gregmulhauser)

    Hi folks,

    If no secondary title has been specified, GHPSEO automatically returns the post’s title as supplied by WordPress. So, if you really want to know when the secondary title field is empty, you could just check whether the value returned by GHPSEO is the same as the value returned by WordPress. (Of course, if you have manually specified the same title in both fields, then this will also make it look like you haven’t specified anything.)

    All the best,
    Greg

    After checking again, you’re right. For some reason, it was returning empty strings before. Thanks!

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘[Plugin: Greg's High Performance SEO] Secondary title repeats main’ is closed to new replies.