- This topic has 9 replies, 2 voices, and was last updated 8 years, 7 months ago by Tom.
Viewing 10 posts - 1 through 10 (of 10 total)
-
AuthorPosts
-
August 30, 2015 at 9:34 am #133120Pete
How would I edit this code to suffix the post title with the author’s nickname (display name) AND keep the current post ID suffix as well?
add_filter( 'the_title', 'gowp_post_id_title_suffix' ); // registers our action filter; the 2nd parameter is the name of the function we'll use to return the (possibly) updated title function gowp_post_id_title_suffix( $title ) { global $post; // get the current post object if ( ( 'job_listing' == $post->post_type ) && in_the_loop() ) { // only apply our change to Posts while in the loop $title .= " #{$post->ID}"; // append the post ID to the title } return $title; // return the title, even if we haven't modified it }
August 30, 2015 at 10:34 am #133140TomLead DeveloperLead DeveloperThis isn’t exactly GP General Support π
Something like this may work?
add_filter( 'the_title', 'gowp_post_id_title_suffix' ); // registers our action filter; the 2nd parameter is the name of the function we'll use to return the (possibly) updated title function gowp_post_id_title_suffix( $title ) { $user_nickname = get_the_author_meta( 'nickname' ); global $post; // get the current post object if ( ( 'job_listing' == $post->post_type ) && in_the_loop() ) { // only apply our change to Posts while in the loop $title .= " #{$post->ID} {$user_nickname}"; // append the post ID to the title } return $title; // return the title, even if we haven't modified it }
August 30, 2015 at 10:36 am #133141PeteSorry Tom π
August 30, 2015 at 10:37 am #133142TomLead DeveloperLead DeveloperNo worries! Let me know if that works or not π
August 30, 2015 at 10:38 am #133143PeteNothing changed
August 30, 2015 at 11:41 pm #133231TomLead DeveloperLead DeveloperHmm.. How about:
add_filter( 'the_title', 'gowp_post_id_title_suffix' ); // registers our action filter; the 2nd parameter is the name of the function we'll use to return the (possibly) updated title function gowp_post_id_title_suffix( $title ) { $user_nickname = get_the_author_meta( 'nickname' ); global $post; // get the current post object if ( ( 'job_listing' == $post->post_type ) && in_the_loop() ) { // only apply our change to Posts while in the loop $title .= ' #' . $post->ID . ' ' . $user_nickname; // append the post ID to the title } return $title; // return the title, even if we haven't modified it }
You may have to adjust the $user_nickname variable using this function to debug: https://codex.wordpress.org/Function_Reference/get_the_author_meta
August 31, 2015 at 2:03 am #133241PeteA big fat white screen π It’s ok I’ll hunt it down on the WP support forum. Thanks anyway.
August 31, 2015 at 10:58 am #133320TomLead DeveloperLead DeveloperReally? I’m not seeing what could cause a white screen – were there any errors?
August 31, 2015 at 10:41 pm #133417PeteNope just white.
August 31, 2015 at 11:14 pm #133427TomLead DeveloperLead DeveloperThat’s the worst – what about with WP DEBUG turned on?: http://codex.wordpress.org/WP_DEBUG
-
AuthorPosts
Viewing 10 posts - 1 through 10 (of 10 total)
- You must be logged in to reply to this topic.