I'm not quite sure how it works, if you're on a post (single.php), does it count page.php as the page it's on?

What i need to do, is get a custom field assigned to a page, from a blog post. I need it because i want the user to be able to change the "Read more" text in the post excerpt.

I could get the custom field by just using a static page id, but if the user decides to change things up the id might change, i need it to be dynamic.

What would be the best way to go about this?


2 Answers 2


I would suggest a different approach. The option for manually adding post excerpt should go in a theme option as opposed to a custom field. Also you should use this hook for modifying the excerpt's more text


If the user is supposed to enter custom excerpt on a per-post basis, they can do it from the admin panel anyway.

  • The excerpt isn't manually added, it's just a cropped version of the entire text (default). The custom_excerpt_more() function only works from the functions.php right? I need to have the user be able to set their own Read more text on the blog page (not the post page), and then display it after each excerpt.
    – qwerty
    Oct 16, 2012 at 12:16
  • I meant that you should give the user a theme option where they may enter the text they want. Then in the custom_excerpt_more() function in functions.php, you'll read the text that user entered, sanitize it, & add it. Oct 16, 2012 at 12:25
  • Please note that excerpt_more hook is not called if the excerpt is not actually trimmed from the content. If you want to guarantee that Read More text is always displayed use the_excerpt hook instead or you can just display it directly inside template files (single.php, page.php etc.) Oct 16, 2012 at 12:28
  • That would work, but i'm afraid it's too complex for the end user. It has to bee as simple as possible. The user shouldn't have to ever go to the themes settings to change something. (Not my rules) Is it possible to get the custom field of the blog page from the single (blog post) page?
    – qwerty
    Oct 16, 2012 at 12:30
  • 1
    get_option('page_for_posts') would return the blog page's id. Then you can do something like get_post_meta( get_option('page_for_posts'), 'customfield', true ); Oct 16, 2012 at 12:39

This will work.Add this lines in functions.php file

 function custom_excerpt_more( $more ) {
       global $post;
       $key_1_values = get_post_meta($post_id, $key, $single);
        return $more;
    add_filter( 'excerpt_more', 'custom_excerpt_more' );
  • No, this won't work. $post_id and $single are set nowhere.
    – kaiser
    Oct 16, 2012 at 13:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.