I’m trying to append some php code to the_content
in a custom loop. I do not want to add a function because I only want to append the code to one instance of the_content
, not throughout the whole site.
I’m using the Read More Right Here plugin to enable viewers to read a whole post (after clicking the more tag) that displays on the page (without going to single post). And I’m using the Advanced Custom Fields plugin to output some content (when a check box is ticked in the back end) that I want to display at the end of each post. If I place my code to output the check box data AFTER the_content
in my template, the info is displayed underneath the more tag. My aim is to append this to the bottom of the_content
so that it is hidden (along with the rest of the post after the more tag) until you click ‘read more’ (and the rest of the post is revealed).
The code I am trying to append to the end of the_content
is:
<?php
if( in_array( 'frazer-barton', get_field('who_specialises') ) )
{
echo '<img src="http://andersonlloyd.php.wired.co.nz/wp-content/themes/all/images/example-thumb.jpg" />';
}
if( in_array( 'sarah-simmers', get_field('who_specialises') ) )
{
echo '<img src="http://andersonlloyd.php.wired.co.nz/wp-content/themes/all/image/example2-thumb.jpg" />';
}
else {
echo '';
}
?>
I am not a PHP developer so any help on this is hugely appreciated.
You are looking to filter
the_content
.In your theme’s functions.php or in a plugin:
As an aside, this question is probably the dupe of a dupe of a dupe [+ n dupes], had you known what to search for.