0

I want to show following HTML code in the place of excerpt in WordPress. In original code WordPress use

return '...';

I want to add following PHP and HTML code on return:

 <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>

Maybe following is the complete code of that function

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;

1 Answer 1

1

Put your html in a .php file. Then write this

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

And then return $out. This will include your html inside you $out var, when you return it via ajax or whatever your method is, you just have to inject it in your page.

Sign up to request clarification or add additional context in comments.

2 Comments

else if ( $stack == 'ethos' ) { ob_start(); include 'shareicr.php'; $out = ob_get_contents(); ob_end_clean(); }
You forgot the return $out;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.