- This topic has 9 replies, 2 voices, and was last updated 5 years, 6 months ago by
Tom.
-
AuthorPosts
-
August 30, 2015 at 9:34 am #133120
Pete
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 #133140Tom
Lead 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 }
Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/
Ongoing Development: https://generatepress.com/ongoing-developmentAugust 30, 2015 at 10:36 am #133141Pete
Sorry Tom π
August 30, 2015 at 10:37 am #133142Tom
Lead DeveloperLead DeveloperNo worries! Let me know if that works or not π
Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/
Ongoing Development: https://generatepress.com/ongoing-developmentAugust 30, 2015 at 10:38 am #133143Pete
Nothing changed
August 30, 2015 at 11:41 pm #133231Tom
Lead 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
Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/
Ongoing Development: https://generatepress.com/ongoing-developmentAugust 31, 2015 at 2:03 am #133241Pete
A 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 #133320Tom
Lead DeveloperLead DeveloperReally? I’m not seeing what could cause a white screen – were there any errors?
Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/
Ongoing Development: https://generatepress.com/ongoing-developmentAugust 31, 2015 at 10:41 pm #133417Pete
Nope just white.
August 31, 2015 at 11:14 pm #133427Tom
Lead DeveloperLead DeveloperThat’s the worst – what about with WP DEBUG turned on?: http://codex.wordpress.org/WP_DEBUG
Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/
Ongoing Development: https://generatepress.com/ongoing-development -
AuthorPosts
- You must be logged in to reply to this topic.