Support » Theme: Path » How can I include user_submit_name value in the post

Viewing 7 replies - 1 through 7 (of 7 total)
  • Theme Author Sami Keijonen

    (@samikeijonen)

    Where would you like to appear that? And do you have a code snippet from plugin author how to get user_submit_name?

    This will have to show up in a post (content).

    Here is the code used to call the name from the custom field

    <?php if (function_exists('usp_author_link')) usp_author_link(); ?>

    Theme Author Sami Keijonen

    (@samikeijonen)

    Try something like this in your custom plugin or in child theme functions.php. Code is not tested so do not try it on live site.

    function my_filter_content( $content ) {
    
       if( is_singular( 'post' ) && is_main_query() ) {
    
          if ( function_exists( 'usp_author_link' ) ) {
             $new_content = usp_author_link();
             $content .= $new_content;
          }
    
       }	
    
       return $content;
    }
    add_filter( 'the_content', 'my_filter_content' );

    Thank you Sami but I still end up with a post where name and content are not one continuous line

    “user_submit_name here”

    writes: Blaa blaa blaa aka what ever he wrote

    function my_filter_content( $content ) {
    
    //        if( is_singular( 'post' ) && is_main_query() ) {
    
              if ( function_exists( 'usp_author_link' )) {
                 $new_content = usp_author_link();
                 $content .= $new_content;
    //           }
    
           }	
    
           return $content;
        }
        add_filter( 'the_content', 'my_filter_content' );

    I also commented out the is_singular part

    here is an example, how it works exactly as needed:
    Everything is in one line, author name shows up only if submitted by regular user or anonymous user.
    from: http://wordpress.org/support/topic/how-can-i-include-user_submit_name-value-in-the-post?replies=3

    // USP prefix submitted content
    function my_the_content_filter($content) {
    	global $post;
    	$usp_author = get_post_meta($post->ID, 'user_submit_name', true);
    	if (usp_is_public_submission()) {
    		$content = $usp_author . ' writes: ' . $content;
    	}
    	return $content;
    }
    add_filter('the_content', 'my_the_content_filter');

    here is change I made to my child-theme content.php:

    ...
    </header><!-- .entry-header -->
    
    		<div class="entry-content">
    		<?php if (function_exists('usp_author_link')) usp_author_link(); ?>
    		<?php echo $post->post_content = ' writes: ' . $post->post_content; ?>
    
     			<?php /*the_content(); */?>
    <div class="entry-content">
    		<?php if (function_exists('usp_author_link')) usp_author_link(); ?>
    		<?php echo $post->post_content = ' kirjutas: ' . $post->post_content; ?>
    
     			<?php /*the_content();*/ ?>

    This is not working if you have a image in your post. 🙁

    Any advice is welcome.

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘How can I include user_submit_name value in the post’ is closed to new replies.