Title: shortcode function
Last modified: August 20, 2016

---

# shortcode function

 *  Resolved [danielpol](https://wordpress.org/support/users/danielpol/)
 * (@danielpol)
 * [15 years, 1 month ago](https://wordpress.org/support/topic/shortcode-function/)
 * Hi guys
    I have an issue with this function [http://pastebin.com/JSxsQKQt](http://pastebin.com/JSxsQKQt)
 * What the function does is to replace the shortcode from a page with specified
   post title. The shortcode from the page is like [[`123`]] , where `123` is the
   ID of the post.
    It works but needs a little tweaking and my php skills suck.
   It returns the titles like `<li> title </li>` but I want all the `<li>` inside`
   <ul> ... </ul>`. The `return $content;` returns not just the `<li>title</li>`
   but also the content of the page where the shortcode is .
 * Anyone can help ?
    Thanks

Viewing 9 replies - 1 through 9 (of 9 total)

 *  [shahar](https://wordpress.org/support/users/shahar/)
 * (@shahar)
 * [15 years, 1 month ago](https://wordpress.org/support/topic/shortcode-function/#post-2086172)
 * Hi, please take a look here:
    [http://pastebin.com/P1EXiNaT](http://pastebin.com/P1EXiNaT)
 * I added 2 lines around `$postTitleText` (line 20, 22).
 * This will only work if your shortcodes are next to each other, if you have other
   text in between it will wrap it all in the `</ul>`
 * Hope it helps!
 *  Thread Starter [danielpol](https://wordpress.org/support/users/danielpol/)
 * (@danielpol)
 * [15 years, 1 month ago](https://wordpress.org/support/topic/shortcode-function/#post-2086228)
 * shabar I added the 2 lines but bothing happens, it’s the same with or without
   the 2 lines.
    Thanks for your time.
 *  [shahar](https://wordpress.org/support/users/shahar/)
 * (@shahar)
 * [15 years, 1 month ago](https://wordpress.org/support/topic/shortcode-function/#post-2086233)
 * Did you change line 21 too? You need to add the ‘.’ like this:
 * `$postTitleText .=`
 *  Thread Starter [danielpol](https://wordpress.org/support/users/danielpol/)
 * (@danielpol)
 * [15 years, 1 month ago](https://wordpress.org/support/topic/shortcode-function/#post-2086234)
 * oops, sorry.
    changed it now but still doesn’t work as expected I get this
 *     ```
       <ul>
           <li>...</li>
           <li>...</li>
        <ul>
       <ul>
           <li>...</li>
           <li>...</li>
            the page content
        <ul>
       ```
   
 * This is strange
 *  [shahar](https://wordpress.org/support/users/shahar/)
 * (@shahar)
 * [15 years, 1 month ago](https://wordpress.org/support/topic/shortcode-function/#post-2086235)
 * Can you paste the post content so I can see what you’re running this on?
 * I used something like this and it worked:
 *     ```
       Page content here
       12
       ```
   
 *  Thread Starter [danielpol](https://wordpress.org/support/users/danielpol/)
 * (@danielpol)
 * [15 years, 1 month ago](https://wordpress.org/support/topic/shortcode-function/#post-2086236)
 * This is what i have
 *     ```
       866  841  866  841
       <h4>Lorem ipsum </h4>
       .............
       ............
       ```
   
 *  [shahar](https://wordpress.org/support/users/shahar/)
 * (@shahar)
 * [15 years, 1 month ago](https://wordpress.org/support/topic/shortcode-function/#post-2086238)
 * Because you’re replacing a particular post id using the regular expression, it
   will replace each occurrence of the post id at the same time.
 * So. If you try [[866]] [[841]] only the code should work fine.
 * The problem in the example is that both times [[866]] occurs it is being replaced
   by the link that logically opens the`<ul>`.
 * Does that make sense? Please try without duplicate post ids, it should work.
 *  Thread Starter [danielpol](https://wordpress.org/support/users/danielpol/)
 * (@danielpol)
 * [15 years, 1 month ago](https://wordpress.org/support/topic/shortcode-function/#post-2086240)
 * Ah, it WORKS. Silly me 🙂
    Thanks a lot shabar. I owe you
 *  [shahar](https://wordpress.org/support/users/shahar/)
 * (@shahar)
 * [15 years, 1 month ago](https://wordpress.org/support/topic/shortcode-function/#post-2086242)
 * My pleasure.
    That’s what the forums are for 😀

Viewing 9 replies - 1 through 9 (of 9 total)

The topic ‘shortcode function’ is closed to new replies.

 * In: [Hacks](https://wordpress.org/support/forum/plugins-and-hacks/hacks/)
 * 9 replies
 * 2 participants
 * Last reply from: [shahar](https://wordpress.org/support/users/shahar/)
 * Last activity: [15 years, 1 month ago](https://wordpress.org/support/topic/shortcode-function/#post-2086242)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
