0

I have this type of 8 block of <div> so I want to convert it into shortcode :

<div class="homebx01 clearfix ani-1">
        <div class="homebxhead clearfix">
          <div class="bxicon homebxicon01"></div>
          <div class="bxheadtxt">Category name</strong></div>
        </div>
        <div class="cl"></div>
        <div class="homebxbody clearfix">
          <ul class="bxulsty">
            <li class="clearfix"><span></span> <strong>Category Description</strong></li>
          </ul>
        </div>
        <div class="cl"></div>
        <a class="morebt clearfix" href="#">Link to particular Categories post.</a> 
</div>
<div class="homebx01 clearfix ani-1">
        <div class="homebxhead clearfix">
          <div class="bxicon homebxicon01"></div>
          <div class="bxheadtxt">Category name</strong></div>
        </div>
        <div class="cl"></div>
        <div class="homebxbody clearfix">
          <ul class="bxulsty">
            <li class="clearfix"><span></span> <strong>Category Description</strong></li>
          </ul>
        </div>
        <div class="cl"></div>
        <a class="morebt clearfix" href="#">Link to particular Categories post.</a> 
</div>
<div class="homebx01 clearfix ani-1">
        <div class="homebxhead clearfix">
          <div class="bxicon homebxicon01"></div>
          <div class="bxheadtxt">Category name</strong></div>
        </div>
        <div class="cl"></div>
        <div class="homebxbody clearfix">
          <ul class="bxulsty">
            <li class="clearfix"><span></span> <strong>Category Description</strong></li>
          </ul>
        </div>
        <div class="cl"></div>
        <a class="morebt clearfix" href="#">Link to particular Categories post.</a> 
</div>

Help me that how to convert my this php code into shortcode to add in the page?

3

The basics of creating a shortcode are quite simple. You just need to create a function that returns the code you want to output in a string and register that function:

function wpse_143641_homebox_shortcode( $atts ) {
  return <<<HOMEBOX
<div class="homebx01 clearfix ani-1">
  <div class="homebxhead clearfix">
    <div class="bxicon homebxicon01"></div>
    <div class="bxheadtxt">Category name</strong></div>
  </div>
  <div class="cl"></div>
  <div class="homebxbody clearfix">
    <ul class="bxulsty">
      <li class="clearfix"><span></span> <strong>Category Description</strong></li>
    </ul>
  </div>
  <div class="cl"></div>
  <a class="morebt clearfix" href="#">Link to particular Categories post.</a> 
</div>
<div class="homebx01 clearfix ani-1">
  <div class="homebxhead clearfix">
    <div class="bxicon homebxicon01"></div>
    <div class="bxheadtxt">Category name</strong></div>
  </div>
  <div class="cl"></div>
  <div class="homebxbody clearfix">
    <ul class="bxulsty">
      <li class="clearfix"><span></span> <strong>Category Description</strong></li>
    </ul>
  </div>
  <div class="cl"></div>
  <a class="morebt clearfix" href="#">Link to particular Categories post.</a> 
</div>
<div class="homebx01 clearfix ani-1">
  <div class="homebxhead clearfix">
    <div class="bxicon homebxicon01"></div>
    <div class="bxheadtxt">Category name</strong></div>
  </div>
  <div class="cl"></div>
   <div class="homebxbody clearfix">
    <ul class="bxulsty">
      <li class="clearfix"><span></span> <strong>Category Description</strong></li>
    </ul>
  </div>
  <div class="cl"></div>
  <a class="morebt clearfix" href="#">Link to particular Categories post.</a> 
</div>
HOMEBOX;
}
add_shortcode( 'homebox', 'wpse_143641_homebox_shortcode' );

Further examples and details about how to accept aguments and such are available in the Shortcode_API codex docs.

  • Thnk u very much.. its working.. (y) – daxter May 8 '14 at 4:34

Not the answer you're looking for? Browse other questions tagged or ask your own question.