the_content后按自定义按钮链接输出



>我正在尝试插入一个按钮,以显示在Wordpress上每篇文章的末尾,其中它所指向的链接由使用自定义字段插件的设置定义。创建每个帖子时,我能够选择要显示的链接。

这是我的代码,我知道它是错误的,但我希望有人能在这里提供帮助。

function wpb_after_post_content($content){
if (is_single()) {
$content .= '<a href="'franchise_profile_url'); ?>" target="_blank" class="franchise-profile-btn">Contact Franchise &rarr;</a>';
}
return $content;
}
add_filter( "the_content", "wpb_after_post_content" );

我假设$franchise_profile_url是一个变量,你应该像这样在字符串中连接它

$content .= '<a href="'.$franchise_profile_url.'" target="_blank" class="franchise-profile-btn">Contact Franchise &rarr;</a>';
function afterContent($content) {
if(!is_feed() && !is_home()) {
$content.= "<div class='footNote'>";
$content.= "<h4>Click the below button if you like it:</h4>";
$content.= "<p><a href='#'>LIKE</a></p>";
$content.= "</div>";
}
return $content;
}
add_filter ('the_content', 'afterContent');

使用上述功能。它将帮助您实现所需的目标。

但是,感谢您在此处的帮助,该代码只是链接回帖子本身,而不是使用自定义字段拉入帖子上设置的URL。这是我之前设置的代码,它正在处理默认的后期设置,但现在我希望在函数.php文件中使用替代方法

<?php if( get_field('franchise_profile_url') ): ?>
<a href="<?php the_field('franchise_profile_url'); ?>" target="_blank" class="franchise-profile-btn">Contact Franchise &rarr;</a>
<?php endif; ?>

最新更新