如何在返回函数中添加此 HTML PHP 代码


How to add this HTML PHP code in return function?

我想在WordPress中显示以下HTML代码来代替摘录。在原始代码中WordPress使用

return '...';

我想在返回时添加以下 PHP 和 HTML 代码:

 <div class="share-icons-r">
     <div class="share-r">
      <h3>Share</h3>
     </div>
     <div class="icons-r">
      <a target="_blank" href="http://www.facebook.com/share.php?u=<?php echo get_permalink();?>&title=<?php the_title(); ?>">
      <img src="http://www.mywebsite.com/fb.png" />
      </a>
     </div>
 </div>

也许以下是该函数的完整代码

if ( ! function_exists( 'x_excerpt_string' ) ) :
function x_excerpt_string( $more ) 
{ 
$stack = x_get_stack();
   if ( $stack == 'integrity' ) 
      {
   return ' ... <div><a href="' . get_permalink() . '" class="more-link">' . __( 'Read More', '__x__' ) . '</a>
</div>';} 

else if ( $stack == 'renew' )
  {
  return ' ... <a href="' . get_permalink() . '" class="more-link">' . __( 'Read More', '__x__' ) . '</a>';} 
else if ( $stack == 'icon' ) 
  {
  return ' ...';
  } 
  else if ( $stack == 'ethos' ) 
  {
  return '...';
  }
}
add_filter( 'excerpt_more', 'x_excerpt_string' );
endif;

把你的html放在一个.php文件中。然后写这个

ob_start();
include 'my_htlm.php';
$out = ob_get_contents();
ob_end_clean();

然后返回$out。这将包括你的html在你$out var,当你通过ajax或任何你的方法返回它时,你只需要在你的页面中注入它。