Title: Applying shortcode actions
Last modified: February 28, 2017

---

# Applying shortcode actions

 *  [rudym](https://wordpress.org/support/users/rudym/)
 * (@rudym)
 * [9 years, 1 month ago](https://wordpress.org/support/topic/applying-shortcode-actions/)
 * Hi all,
 * I have a plugin that will apply the changes desired, but only if I apply a shortcode
   to the areas I will need them. However, I would rather not have to tell the user
   to wrap their content with a shortcode. How can I bypass this, and just make 
   it so that the content behaves as if the shortcode were there?
 * Basicall, the plugin will currently apply the changes I want to links wrapped
   in a shortcode, e.g., [blahblah_shortcode]https://www.google.com[/blahblah_shortcode].
   BUT I would rather not have to use the shortcode to apply this behavior. How 
   can I accomplish this.
 * Thanks.

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

 *  Moderator [Steven Stern (sterndata)](https://wordpress.org/support/users/sterndata/)
 * (@sterndata)
 * Volunteer Forum Moderator
 * [9 years, 1 month ago](https://wordpress.org/support/topic/applying-shortcode-actions/#post-8858091)
 * If you were searching for the content, could you definitively identify it without
   a shortcode? If so, you can write a filter on the_content and “magically” adjust
   that piece of it.
 * [https://developer.wordpress.org/reference/hooks/the_content/](https://developer.wordpress.org/reference/hooks/the_content/)
 * If not, you need the shortcode.
 *  Thread Starter [rudym](https://wordpress.org/support/users/rudym/)
 * (@rudym)
 * [9 years, 1 month ago](https://wordpress.org/support/topic/applying-shortcode-actions/#post-8858313)
 * I guess I’d need a regex to identify the targets, it would be all where the href
   points to a PDF. I’ll check out the link you posted, thanks!
 *  Thread Starter [rudym](https://wordpress.org/support/users/rudym/)
 * (@rudym)
 * [9 years, 1 month ago](https://wordpress.org/support/topic/applying-shortcode-actions/#post-8858842)
 * [@sterndata](https://wordpress.org/support/users/sterndata/),
 * Thanks again. I tried adding the filter, and seems to work okay. HOWEVER, in 
   the plugin code, I was working with a creating, setting, and checking the value
   for a $_SESSION variable. How would this work now since now I’ve managed to eliminate
   the need for the shortcode? Below is a breakdown of the changes I made:
 * In the main PHP code for the plugin, I added `add_filter( 'the_content', 'hash_links');`
   in one of the functions that get called upon instantiation.
 * I then added the following functions OUTSIDE the plugin class:
 *     ```
       // Replace all PDF links with the hash values.
       function hash_links( $content ) {
         $regex = "/(http|https|ftp|ftps)\:\/\/[a-zA-Z0-9\-\.]+\.[a-zA-Z]{2,3}(\/\S*\.pdf)+/";
   
         preg_match_all($regex, $content, $link_matches);
   
         $content .= "<BR><BR><BR>";
   
         foreach($link_matches[0] as $match){
           $content = str_replace($match, hashLink($match), $content);
         }
   
         return $content;
       }
   
       // This will return the hash value for the link. Here, we will also add the hash value and plaintext to the option table.
       function hashLink($link) {
         $ins = $GLOBALS['reCaptchaProtectedDownloadsCore'];
         $hash = apply_filters("rcpdl_hash", md5($link), $link);
   
         if ( $ins->isNetworkActive() ){
           add_site_option("rcpdl_{$hash}", esc_attr(esc_url( $link )));
         } else{
           add_option("rcpdl_{$hash}", esc_attr(esc_url( $link )));
         }
   
         return apply_filters('rcpdl_link', "#rcpdl={$hash}", $link, $hash);
       }
       ```
   
 *  Moderator [Steven Stern (sterndata)](https://wordpress.org/support/users/sterndata/)
 * (@sterndata)
 * Volunteer Forum Moderator
 * [9 years, 1 month ago](https://wordpress.org/support/topic/applying-shortcode-actions/#post-8859054)
 * Sorry, I have no idea.
 *  Thread Starter [rudym](https://wordpress.org/support/users/rudym/)
 * (@rudym)
 * [9 years, 1 month ago](https://wordpress.org/support/topic/applying-shortcode-actions/#post-8859135)
 * Ah, got it. What I had was actually SESSION info **AND** a javascript variable
   that controlled the link behavior. The javascript variable kept being reset because
   the link would open in the same window/tab, thereby refreshing the page on return,
   and the javascript with it.
 * In short, I just had to change it so that the links open in new tabs/windows 
   instead. Thanks again for your help in resolving my first issue.

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

The topic ‘Applying shortcode actions’ is closed to new replies.

 * In: [Developing with WordPress](https://wordpress.org/support/forum/wp-advanced/)
 * 5 replies
 * 2 participants
 * Last reply from: [rudym](https://wordpress.org/support/users/rudym/)
 * Last activity: [9 years, 1 month ago](https://wordpress.org/support/topic/applying-shortcode-actions/#post-8859135)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
