Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • #1295905

    I need a solution to limit or display only first word of post title only on homepage in my blog using enfold.

    site: copybloggerthemes.com

    Example of a post: Holiday WordPress Theme Free Download

    Now, i want to display only Holiday word as post title only on homepage of a website. But the title should be complete on all other pages. Same like that to be applied on all post titles on homepage.

    I have tried this code but it does not work

    add_filter( 'the_title', 'wpse_75691_trim_words' );
    
    function wpse_75691_trim_words( $title )
    {
        // Limit the title to exactly one word only on the home page.
        if (is_home()) {
            return wp_trim_words( $title, 1, '' );
        }
        // Otherwise return the full title.
        return $title; 
    }

    Kindly do let me know, where is the error why the code is not working with enfold ?
    i hope someone would help me soon. thanks

    • This topic was modified 3 years, 8 months ago by hamzakhankhan.
    #1296462

    Hi Hafeez,

    You could try the is_front_page conditional instead: https://developer.wordpress.org/reference/functions/is_front_page/

    Best regards,
    Rikard

    #1297749

    @Rikard Hello

    I have used the condition is_front_page/ and it worked but it effected the Menu Title & Blog Main Title while i want to apply it to the posts title on my website frontpage. It still not applied to the posts title.

    add_filter( 'the_title', 'wpse_75691_trim_words' );
    
    function wpse_75691_trim_words( $title )
    {
        // Limit the title to exactly one word only on the frontpage.
        if (is_front_page()) {
            return wp_trim_words( $title, 1, '' );
        }
        // Otherwise return the full title.
        return $title; 
    }

    My Posts Title on frontpage Looked like this you can see it in inspect element;
    screenshot: https://prnt.sc/12dd3tq

    Hint: As you see in the screenshot the post title are using h3 tag, So if you could add h3 title function something to my existing coding then it will be applied only to the h3 title of my posts title and will not effect any other title tags on my website.

    Thanks and hope to see you with coding!

    #1298201

    Hi,

    Thank you for the update.

    The filter accepts a second parameter, which is the $id of the post. You can use that to check if the current post is not a menu item or if it an actual post using the get_post_type function.

    add_filter( 'the_title', 'wpse_75691_trim_words' );
    
    function wpse_75691_trim_words( $title, $id )
    {
        // Limit the title to exactly one word only on the frontpage.
        if (is_front_page() && get_post_type( $id ) == "post" ) {
            return wp_trim_words( $title, 1, '' );
        }
        // Otherwise return the full title.
        return $title; 
    }

    Best regards,
    Ismael

    #1301744

    Hi, Ismael

    I have tried the code but it break the overall site, i have used the below code but it disturb the top menu title and display the menu first word, while i want to display the first word of post title on frontpage.

    add_filter( 'the_title', 'wpse_75691_trim_words' );
    
    function wpse_75691_trim_words( $title)
    {
        // Limit the title to exactly one word only on the frontpage.
        if (is_front_page()) {
            return wp_trim_words( $title, 1, '' );
        }
        // Otherwise return the full title.
        return $title; 
    }

    I have tested the code on other themes it work fine but not working with enfold,
    I want like this see screenshot: https://prnt.sc/139b24a

    I am providing the site link and password with login in private, Kindly check and resolve the issue for me, Thanks

    Please help me: @Rikard, @Ismael @Nikko

    • This reply was modified 3 years, 7 months ago by hamzakhankhan.
    #1301905

    Hi hamzakhankhan,

    Can you try using this code instead:

    function enfold_postslider_title($title, $entry) {
        if (is_front_page()) {
            return wp_trim_words( $title, 1, '' );
        }
    
        return $title;
    }
    
    add_filter( 'avf_postslider_title', 'enfold_postslider_title', 10, 2 );

    Hope it helps.

    Best regards,
    Nikko

    #1301957

    @Nikko

    You are great Nikko! You always helped & resolve my issue, the post titles are now displaying first word on frontpage. Thanks bundles.

    Outstanding Support

    #1301960

    Hi,

    Glad Nikko could help! :)

    For your information, you can take a look at Enfold documentation here – https://kriesi.at/documentation/enfold/

    If you have any other questions or issues, feel free to start a new thread under Enfold sub forum and we will gladly try to help you :)

    Enjoy the rest of your day!

    Best regards,
    Yigit

Viewing 8 posts - 1 through 8 (of 8 total)
  • The topic ‘How to Display First Word as Post Title only on Homepage in Enfold’ is closed to new replies.