[Resolved] Different entry title

Home Forums Support [Resolved] Different entry title

Home Forums Support Different entry title

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #2391429
    webintas

    Hi there,

    I want to have the entry title to be something else than the post title. The post title is often short and used for menu item labels and <title> tag.

    However I would like to have the h1 entry title on the page/post be longer and more specific. How can the post title and entry title be different?

    Best Regards,
    Peter

    #2391477
    David
    Staff
    Customer Support

    Hi there,

    you would need somewhere to store the shortened Post Title.
    Do you use any plugins for adding custom fields, such as ACF or Meta box ?

    #2392369
    webintas

    Hi David,

    I prefer ACF.

    #2392727
    David
    Staff
    Customer Support

    Ok, so you need to create an ACF Field to add your title text.
    It will be easier if this stores the Long title, otherwise there are some many other places where to update the other title.

    Then try this PHP Snippet:

    
    function db_swap_content_title( $title ) {
        $long_title = get_field( 'your_acf_title_field' );
        
        if (is_admin() || !in_the_loop() || !$long_title  ) {
            return $title;
        }
        
        return $long_title;
    }
    
    add_filter( 'the_title', 'db_swap_content_title' );

    You need to update your your_acf_title_field

    This in theory should replace only the content title within the loop so it will affect single and archives.

    #2401459
    webintas

    Awesome, thank you! 🙂

    #2401472
    David
    Staff
    Customer Support

    You’re welcome

Viewing 6 posts - 1 through 6 (of 6 total)
  • You must be logged in to reply to this topic.