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?

4
  • Please add your code Commented May 7, 2014 at 9:53
  • 2
    I see no PHP in your code, just plain html, what research have you done so far? Commented May 7, 2014 at 10:20
  • 1
    codex.wordpress.org/Function_Reference/add_shortcode ? Commented May 7, 2014 at 10:35
  • 1
    I already gave you your php code to work from. Why you don't want to use it and modify is as I suggested to fit your html output needs, .... Well, it is up to you. The code that you supplied is totally meaningless Commented May 7, 2014 at 10:41

1 Answer 1

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.

1
  • Thnk u very much.. its working.. (y) Commented May 8, 2014 at 4:34

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.