Place text before posts that doesn't get picked up as part of social media snippets

I’d like to place some text (a couple lines of disclosure info) before each post.

But I do not want it to show up on social media snippets, as it will if its the first text in the post.

I tried using PRyC WP to insert the text it before each post, but it shows in social snippets (however it does not show in the index page preview).

What edit can I make to the template to insert a text without it getting picked up in snippets?

Page with current solution: http://eatbeautiful.net/2018/02/25/bulletproof-coffee-intermittent-fasting/

Thank you!

Hello There,

Thanks for writing in!

Is the text consistent in all post? Meaning,this paragraph will display the same wordings in all posts? If that is the case, because what you are trying to accomplish requires a template customization, we would highly to suggest that you use a child theme. This allows you to make code changes that won’t be overwritten when an X update is released.

Tip: After your child theme is setup, please review how we recommend making template changes in Customization Best Practices.

Once the child theme is set up, please add the following code in your child theme’s functions.php file


// Place a custom text
// =============================================================================
function place_custom_text() { ?>
	
	<div class="custom text">
		<p style="font-size: 12px; line-height: 15px; color: #989898;"><i> I may receive a commission if you purchase through links in this post. I am not a doctor; please consult your practitioner before changing your supplement or healthcare regimen. </i></p>
	</div>

<?php }
add_action('x_after_the_content_begin', 'place_custom_text');
// =============================================================================

We would loved to know if this has work for you. Thank you.

Hi.

This technique worked as a way of inserting some text at the top of the post (although arguably no more efficient than using the plugin I was already using.)

However, this alone does not solve my fundamental problem: I don’t want this text to be picked up in social media snippets (which it still is). It looks like this inserts the text “after the content begins”. Is there a place a I can insert it such that it will show up before each post, but it will not be considered “part of the post content” so that it won’t get picked up in social media snippets?Or something with the same outcome.

Hey There,

To make sure that the custom text will not be a part of the content area, you may update the code and use this:

// Place a custom text
// =============================================================================
function place_custom_text() { ?>
	
	<div class="custom text">
		<p style="font-size: 12px; line-height: 15px; color: #989898;"><i> I may receive a commission if you purchase through links in this post. I am not a doctor; please consult your practitioner before changing your supplement or healthcare regimen. </i></p>
	</div>

<?php }
add_action('x_before_the_content_begin', 'place_custom_text');
// =============================================================================

Hope this helps. Kindly let us know.

Hi. I appreciate your help. I have implemented this new code (though I don’t quite understand how it works) and have observed that, while it does insert the text, it still shows up in social snippets like FB. Please see attached image:

What do you think needs to happen to prevent this?

Hi,

You can try this third party plugin

That way you can enter manually the data you want to show in FB

Hello. I am aware of this alternative solution. Just to clarify, does this mean that you do not know of a way to modify the theme to a place consistent text before each post, without including it in the actual post content?

Hi there,

Our theme only follows the Wordpress standard when displaying the content, and it’s part of the_content hook and field. Without including it in the actual post content is quite tricky if it’s going to be dynamic. If it’s going to be static, then the above code will suffice, but yes, you can edit the theme’s template \framework\views\global\_content-the-content.php and add your code before <div class="entry-content content">. If you’ll examine the code, it contains x_before_the_content_begin action hook. Hence, doing this is just the same as the above code, except the above is the easiest.

As a summary, you can’t exclude any text outside the content displayed by Wordpress itself. The theme templates are just a wrapper of the content for styling and layout structure. And you’ll need to customize it to achieve your preferred result.

Thanks!

Hi, placing the content into the _content-the-content.php template before

does do exactly what I want, but of course, since it is outside the dynamic content, it shows on all pages, which I do not want. But I think I understand the situation better now. Thank you for you help!

You’re welcome.

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