Greg's High Performance SEO
[resolved] Secondary title repeats main (4 posts)

  1. drumelt
    Posted 5 years ago #

    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.

  2. Steven Vachon
    Posted 5 years ago #

    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;
  3. gregmulhauser
    Plugin Author

    Posted 5 years ago #

    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,

  4. Steven Vachon
    Posted 5 years ago #

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

Topic Closed

This topic has been closed to new replies.

About this Plugin

  • Greg's High Performance SEO
  • Frequently Asked Questions
  • Support Threads
  • Reviews

About this Topic