How to insert text (affiliate disclosure) in post meta data

Hello,

Hope you can help me. I would like to insert text that would appear next to the meta data of every post to disclose that my site uses affiliate links.

I found this topic: https://theme.co/apex/forum/t/adding-information-to-blog-post-meta/2634 and followed the steps, but then the text appears right under the rest of the meta data - see screenshot.
I would love the text to be to the right of the ‘comments’ and the same size as the rest of the text in that line - is this possible?
Also, when looking at the code provided by your support in this other thread, I was wondering what it means to H1 and H2 tags of the page. Hope this doesn’t have any influence?

Thanks a lot for your help.
PS my site is fullsuitcase.com and I am using x child theme and Ethos pack.

Best regards,
Jurga

Hi There,

It seems you removed the code.

Could you please add it again?

Thanks.

I removed it because I wasn’t sure about the H1and H2 tags and the position/size of the text was not what I wanted. As explained, is it possible to insert the text in line with the other meta data, and without influencing H tags of the page?

Just for information, this was the code I used before:

<?php

// =============================================================================
// VIEWS/ETHOS/_CONTENT-POST-HEADER.PHP
// -----------------------------------------------------------------------------
// Standard <header> output for various posts.
// =============================================================================

?>

<header class="entry-header">
  <?php if ( is_single() ) : ?>
  <h1 class="entry-title"><?php the_title(); ?></h1>
  <?php else : ?>
  <h2 class="entry-title">
    <a href="<?php the_permalink(); ?>" title="<?php echo esc_attr( sprintf( __( 'Permalink to: "%s"', '__x__' ), the_title_attribute( 'echo=0' ) ) ); ?>"><?php the_title(); ?></a>
  </h2>
  <?php endif; ?>
  <?php x_renew_entry_meta(); ?>

  <?php // you can add your text below ?>
  <p>THIS POST CONTAINS AFFILIATE LINKS</p>
</header>

Hi there,

Did you put _content-post-header.php in wp-content/themes/x-child/framework/views/ethos/?

If you already did and the code still does not work. Kindly provide us with the FTP details of your site in a Secure Note.

Thank you.

I did and the code worked. But - once again - I have questions about the H1 and H2 - does this code interfere with the Headings on the post? I am not a programmer but I see H1 and H2 in the code, thus the question.
And second - once again - I would like to be able to put the text to the right of the meta data, not under it. Is this possible? Maybe I need a completely different code placed in a different place to achieve that? See the screenshot of what I am trying to achieve (author, date, comments… and then the text about affiliate links). Thanks

Hi,

The h1 tags will appear on single pages while h2 will appear on index pages.

Please delete the file _content-post-header.php in your child theme then add the code below in your child theme’s functions.php file.

function x_ethos_entry_meta() {

    //
    // Author.
    //

    $author = sprintf( ' %1$s %2$s</span>',
      __( 'by', '__x__' ),
      get_the_author()
    );


    //
    // Date.
    //

    $date = sprintf( '<span><time class="entry-date" datetime="%1$s">%2$s</time></span>',
      esc_attr( get_the_date( 'c' ) ),
      esc_html( get_the_date() )
    );


    //
    // Categories.
    //

    if ( get_post_type() == 'x-portfolio' ) {
      if ( has_term( '', 'portfolio-category', NULL ) ) {
        $categories        = get_the_terms( get_the_ID(), 'portfolio-category' );
        $separator         = ', ';
        $categories_output = '';
        foreach ( $categories as $category ) {
          $categories_output .= '<a href="'
                              . get_term_link( $category->slug, 'portfolio-category' )
                              . '" title="'
                              . esc_attr( sprintf( __( "View all posts in: &ldquo;%s&rdquo;", '__x__' ), $category->name ) )
                              . '"> '
                              . $category->name
                              . '</a>'
                              . $separator;
        }

        $categories_list = sprintf( '<span>%1$s %2$s',
          __( 'In', '__x__' ),
          trim( $categories_output, $separator )
        );
      } else {
        $categories_list = '';
      }
    } else {
      $categories        = get_the_category();
      $separator         = ', ';
      $categories_output = '';
      foreach ( $categories as $category ) {
        $categories_output .= '<a href="'
                            . get_category_link( $category->term_id )
                            . '" title="'
                            . esc_attr( sprintf( __( "View all posts in: &ldquo;%s&rdquo;", '__x__' ), $category->name ) )
                            . '"> '
                            . $category->name
                            . '</a>'
                            . $separator;
      }

      $categories_list = sprintf( '<span>%1$s %2$s',
        __( 'In', '__x__' ),
        trim( $categories_output, $separator )
      );
    }


    //
    // Comments link.
    //

    if ( comments_open() ) {

      $title  = apply_filters( 'x_entry_meta_comments_title', get_the_title() );
      $link   = apply_filters( 'x_entry_meta_comments_link', get_comments_link() );
      $number = apply_filters( 'x_entry_meta_comments_number', get_comments_number() );
      
      $text = ( 0 === $number ) ? 'Leave a Comment' : sprintf( _n( '%s Comment', '%s Comments', $number, '__x__' ), $number );

      $comments = sprintf( '<span><a href="%1$s" title="%2$s" class="meta-comments">%3$s</a></span>',
        esc_url( $link ),
        esc_attr( sprintf( __( 'Leave a comment on: &ldquo;%s&rdquo;', '__x__' ), $title ) ),
        $text
      );

    } else {

      $comments = '';

    }

    
    //
    //Custom Text
    //
    $custom_text = "<span>THIS POST CONTAINS AFFILIATE LINKS</span>";

    //
    // Output.
    //

    if ( x_does_not_need_entry_meta() ) {
      return;
    } else {
      printf( '<p class="p-meta">%1$s%2$s%3$s%4$s%5$s</p>',
        $categories_list,
        $author,
        $date,
        $comments,
        $custom_text
      );
    }

  }

Hope that helps.

Perfect! Just what I needed. Thank you very much

You’re welcome.

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.