• I read your answer here: show custom field
    But how to add a custom field BEFORE the title?
    I want to add the name of the author (for example, Shakespeare, if this is Shakespeare’s verse) BEFORE the code:
    esc_attr( get_the_title() );
    And to be covered by the link.
    I tried to write this:

    $html .= '<h3 class="rpwe-title"><a href="' . esc_url( get_permalink() ) . '" title="' . sprintf( esc_attr__( 'Permalink to %s', 'recent-posts-widget-extended' ), the_title_attribute( 'echo=0' ) ) . '" rel="bookmark">';
    						
    	if ( get_post_meta( get_the_ID(), 'creator', true ) ) :
    	$html .= '<p>';
    		$html .= get_post_meta( get_the_ID(), 'creator', true );
    	$html .= '</p>';
    endif;
    						$html .= '<h3 class="rpwe-title"><a href="' . esc_url( get_permalink() ) . '" title="' . sprintf( esc_attr__( 'Permalink to %s', 'recent-posts-widget-extended' ), the_title_attribute( 'echo=0' ) ) . '" rel="bookmark">';
    						
    	if ( get_post_meta( get_the_ID(), 'creator', true ) ) :
    	$html .= '<p>';
    		$html .= get_post_meta( get_the_ID(), 'creator', true );
    	$html .= '</p>';
    endif;
    esc_attr( get_the_title() );

    But it does not work. Help me please.

    • This topic was modified 6 years, 11 months ago by ledzin.
Viewing 1 replies (of 1 total)
  • text (custom field) and post link? format:

    if ( get_post_meta( get_the_ID(), 'creator', true ) ) :
         $html .= '<p><a href="' . esc_url( get_permalink() ) . '" title="' . sprintf( esc_attr__( 'Permalink to %s', 'recent-posts-widget-extended' ), the_title_attribute( 'echo=0' ) ) . '" rel="bookmark">' . get_post_meta( get_the_ID(), 'creator', true ) . '</a></p>';
    endif;

    code above the line:
    $html .= '<h3 class="rpwe-title"><a href="' . esc_url( get_permalink() ) . '" title="' . sprintf( esc_attr__( 'Permalink to %s', 'recent-posts-widget-extended' ), the_title_attribute( 'echo=0' ) ) . '" rel="bookmark">' . esc_attr( get_the_title() ) . '</a></h3>';

Viewing 1 replies (of 1 total)
  • The topic ‘How to add custom fields?’ is closed to new replies.