• Resolved kaizer01

    (@kaizer01)


    I’m trying to limit the title into 1 word only
    I tried using this code but it doesn’t return anything..

    <?php
           $title = get_the_title();
           $names = explode(' ', $title);
           echo $names[0];
        ?>

    This is where I’m trying to implement the code If I change the get_the_title() into $names[0] but it doesn’t return anything.

    $postheader .= '<h3 class="entry-title"><a href="' . get_permalink() . '" rel="bookmark">' . get_the_title() . '</a></h3>';

Viewing 7 replies - 1 through 7 (of 7 total)
  • Andrew Nevins

    (@anevins)

    WCLDN 2018 Contributor | Volunteer support

    Isn’t get_the_title a function that echos rather than returns?

    Thread Starter kaizer01

    (@kaizer01)

    I really don’t know im confuse about it.

    Andrew Nevins

    (@anevins)

    WCLDN 2018 Contributor | Volunteer support

    Oh no it isn’t, it does return it.
    So what does $title return?

    Thread Starter kaizer01

    (@kaizer01)

    $title return nothing, I think I approach it wrongly that’s why it doesn’t show any value in $names[0].

    I’m trying to put the output inside this code but I really don’t know how
    This is the entire code of it. Please help me.

    if ($show_meta) {
    		$postheader .= '<span class="entry-meta"><span class="entry-comments">' . get_comments_number() . '</span>';
    		$postheader .= '<abbr class="published" title="' . get_the_time('c') . '">' . get_the_time( get_option('date_format') ) . '</abbr></span>';
    	}
    
    	$postheader .= '</a>';
    
    	$postheader .= '</div>';
    
    	$postheader .= '<h3 class="entry-title"><a href="' . get_permalink() . '" rel="bookmark">' . get_the_title() . '</a></h3>';
    
    	return $postheader;
    }

    Andrew Nevins

    (@anevins)

    WCLDN 2018 Contributor | Volunteer support

    Are you familiar with the ‘var_dump’ function in PHP?

    Thread Starter kaizer01

    (@kaizer01)

    not quite…but I think I’ll just rename the title of my wordpress this makes my head hurts ??

    thank you for your replies by the way.

    Thread Starter kaizer01

    (@kaizer01)

    with a little luck in searching this solves everything ??

    wp_trim_words( get_the_title(), 1 )

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Limit the title into 1 word only’ is closed to new replies.