[Resolved] suffix title with multiple functions

Home Forums Support [Resolved] suffix title with multiple functions

Home Forums Support suffix title with multiple functions

Viewing 10 posts - 1 through 10 (of 10 total)
  • Author
    Posts
  • #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
    }
    #133140
    Tom
    Lead Developer
    Lead Developer

    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
    }
    #133141
    Pete

    Sorry Tom πŸ™‚

    #133142
    Tom
    Lead Developer
    Lead Developer

    No worries! Let me know if that works or not πŸ™‚

    #133143
    Pete

    Nothing changed

    #133231
    Tom
    Lead Developer
    Lead Developer

    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

    #133241
    Pete

    A big fat white screen πŸ™‚ It’s ok I’ll hunt it down on the WP support forum. Thanks anyway.

    #133320
    Tom
    Lead Developer
    Lead Developer

    Really? I’m not seeing what could cause a white screen – were there any errors?

    #133417
    Pete

    Nope just white.

    #133427
    Tom
    Lead Developer
    Lead Developer

    That’s the worst – what about with WP DEBUG turned on?: http://codex.wordpress.org/WP_DEBUG

Viewing 10 posts - 1 through 10 (of 10 total)
  • You must be logged in to reply to this topic.