Archived topic
suffix title with multiple functions
9 replies · Started by Pete on August 30, 2015
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
}
This 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
}
Sorry Tom :)
No worries! Let me know if that works or not :)
Nothing changed
Hmm.. 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
A big fat white screen :) It's ok I'll hunt it down on the WP support forum. Thanks anyway.
Really? I'm not seeing what could cause a white screen - were there any errors?
Nope just white.
That's the worst - what about with WP DEBUG turned on?: http://codex.wordpress.org/WP_DEBUG
