Insert Shortcode To All Posts

I had previously implemented a similar situation with the recent posts shortcode, but it was in the old forums. I’ve tried searching here and can’t find it.

Basically, i’d like to implement an ActiveCampaign shortcode [activecampaign form=3] by including it at the end of the content of each post. Rather than go back and put it into a text widget in cornerstone in over 700 posts, i’d like to just edit one of the files that makes it universal. Is that a functions.php code or somewhere else?

Hi @bttrym8,

Thanks for writing in! You can put this code in your child theme’s functions.php:

function my_custom_content() {
  if ( is_singular('post')  ) {
    echo 'My custom content.';
  }
}

add_action( 'x_before_the_content_end', 'my_custom_content' );

Here we’re hooking our custom output into the

x_before_the_content_end

Hope it helps.

Let us know how it goes.

Thanks.

So would the shortcode go in between the apostrophes where “My custom content.” is?

Hi again,

Yes you can add the shortcode in there for example:

function my_custom_content( $content ) {
  if ( is_singular('post') ) {
    echo do_shortcode('[share title="Share this Post" facebook="true" twitter="true" google_plus="true" linkedin="true" pinterest="true" reddit="true" email="true"]');
  }
}
add_action('x_before_the_content_end', 'my_custom_content');

Hope this helps!