Site logo

Archived topic

How to position a Custom Field after a Post Title

3 replies · Started by Peter on February 25, 2022

Viewing posts 1–4 of 4

Hi

I have a custom field which I would like to place next to the post title but it positions the field below the title.
Is there a way for the custom field to sit next to the title?
I've used the generate_after_entry_title and added the shortcode from ACF and tried using a div class to position it but I'm not having any luck.

Many thanks

Pete

Hi there,

do you want the custom field to be output inside the H1 tag ?
If so you can use this PHP Snippet to do that:

add_filter( 'generate_get_the_title_parameters', function( $params ) {
    $subtitle = get_post_meta( get_the_ID(), 'your_custom_field_name', true );
    if ( is_singular() && $subtitle ) {
        $params = array(
	    'before' => sprintf(
	        '<h1 class="entry-title"%1$s>',
		'microdata' === generate_get_schema_type() ? ' itemprop="headline"' : ''
	    ),
	    'after' => sprintf(
		'<span class="custom-subtitle">Enduro Enduro Score: %1$s</span></h1>',
	        $subtitle
            ),
	);
    }
    return $params;
} );

Note this line:

$subtitle = get_post_meta( get_the_ID(), 'your_custom_field_name', true );

You need to change: your_custom_field_name

Thanks David - that worked a treat :)

Glad to hear that

This archived topic is closed to new replies.