• Resolved Gustav

    (@4ever16)


    Im searching for a function which lets me put post number in the post content.
    For example i have 2 posts in my blog.

    Title something (#1)
    Title something else (#2)

    *So besides the title or somewhere else i can see the actual post number. “#1” for the first post “#2” for the second and so on.

    How to?

Viewing 5 replies - 1 through 5 (of 5 total)
  • Hey,

    Could you be more specific where would you like to add the post number? Do you want to add it to the single post or inside the post archive? Also, a link to the page where you’d like to add this element would help me point you to the right solution.

    Thread Starter Gustav

    (@4ever16)

    Something like this: https://imgur.com/a/cehdYKV

    Hi,

    Could you try to add the following code to the functions.php file of your theme?

    function post_title_id_addition( $title, $id = null ) {
        return $title . ' #' . $id;
    }
    add_filter( 'the_title', 'post_title_id_addition', 10, 2 );
    
    Thread Starter Gustav

    (@4ever16)

    It gave me random numbers only.

    Post Title 3 #456
    Post Title 2 #20
    Post Title 1 #15
    Etc…

    • This reply was modified 5 years, 9 months ago by Gustav.

    Hi,

    These numbers at the end of the post titles are not random. This is the order that the posts were created on your website. I suppose that you’d like to add the position of the post title in the page (and maybe you can share a link to that page too)?

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Post number #1’ is closed to new replies.