Title: Shortcode help
Last modified: August 19, 2016

---

# Shortcode help

 *  Resolved [mirrorside](https://wordpress.org/support/users/mirrorside/)
 * (@mirrorside)
 * [15 years, 1 month ago](https://wordpress.org/support/topic/shortcode-help-2/)
 * Hello.
    I want to have a shortcode, where after every 20th word there should 
   be inserted a string: “This post is from Moderator XXX”.
 * [moderatortext] word1-19 “This post is from Moderator XXX” word1-19 ….[/moderatortext]
 * I want this Shortcode exclusively used by my Moderators. This I know how I can
   do/limit.
    But I am clueless about the Shortcode implementation itself.
 * Some simple Shortcodes I’ve already created, so I know the API.
    But I am not
   a PHP expert, and with this special Shortcode I am stuck.

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

 *  [vtxyzzy](https://wordpress.org/support/users/vtxyzzy/)
 * (@vtxyzzy)
 * [15 years, 1 month ago](https://wordpress.org/support/topic/shortcode-help-2/#post-1968304)
 * I do not think this is easy, and maybe not even possible, because of embedded
   punctuation and possible html. However, the code below takes a simplistic approach
   and splits the content on the spaces class:
 *     ```
       function mam_moderated_func ($atts,$content=null) {
       	extract(shortcode_atts(array(
                'noatts' => 'Unknown',
                                       ), $atts));
       	$output = '';
          if (!is_null($content)) {
             preg_match_all('/((\s+)?(\S+))/',$content,$matches);
             foreach ($matches[0] as $match) {
                $output .= $match;
                if (++$count == 20) {
                   $output .= ' MODERATED ';
                   $count = 0;
                }
             }
          }
          return $output;
       }
       add_shortcode('mam_moderated','mam_moderated_func');
       ```
   
 *  Thread Starter [mirrorside](https://wordpress.org/support/users/mirrorside/)
 * (@mirrorside)
 * [15 years ago](https://wordpress.org/support/topic/shortcode-help-2/#post-1968505)
 * It has been late, but thank you very much.
    It is exactly what I intended and
   it works fine.
 * Thank you again for your help.

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

The topic ‘Shortcode help’ is closed to new replies.

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 2 replies
 * 2 participants
 * Last reply from: [mirrorside](https://wordpress.org/support/users/mirrorside/)
 * Last activity: [15 years ago](https://wordpress.org/support/topic/shortcode-help-2/#post-1968505)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
