I'd like to add some code from a single post theme file into a filter but I'm not sure how to do it because it includes the get_post_meta() function. I've searched but can't seem to figure it out.
Code in single-post.php
theme file:
$apoth_original_title = get_post_meta( get_the_ID(), 'original_blog_title', true);
$apoth_original_url = get_post_meta( get_the_ID(), 'original_url', true);
?>
<a id="apoth_readmore" class="w-btn style_solid size_medium color_primary icon_none" href="<?php echo $apoth_original_url?>"><span class="w-btn-label">Read More at <em><?php echo $apoth_original_title ?></em></span></a>
<?php
Attempted filter in functions.php
:
function apoth_readmore_link( $content ) {
if( is_single() ) {
$content .= '<a href="' . get_post_meta(get_the_ID(), 'original_url', true) . '"> Read More</a>' ;
}
return $content;
}
add_filter('the_content', 'apoth_readmore_link' )
I get that this isn't working because get_post_meta()
doesn't echo the custom field data, but I don't know how to assign that to a variable and then echo it in the context of a filter function. Or maybe there is some other way of doing this that I'm missing?
original_blog_title
andoriginal_url
fromfunctions.php
then render the link with filtered content?