Bringing Shortcodes to Drupal
One of the things I love the most from Wordpress is the ability to define custom shortcodes on your theme's functions.php. This is possible on Drupal, but as with most things with my favorite CMS, it is more powerful but requires more work to set it up.
Ingredients
- Custom Filters
- Basic Regex.
Creating a Shortcode
Once you have Custom Filters enabled, go to the module page and add a new filter. Name it the way you want, and click save. Once you are back in the filters list, click on the one you just created so we can create a rule.
/\[checkmark]/i
Now, our image will be located in our theme folder and we won't be using PHP parsing, so we just insert:
<img src="/sites/all/themes/THEME/images/checkmark.png" />
into the replacement text box.
Now, we just need to enable our custom filter in Text Formats options. Go to Text Formats, select the one you are currently using and under Enabled Filters, locate and select the one you just created.
latest posts
About
Hi, I'm Ivan Soto Fernandez (yes, two last names). I'm a chilean web developer living in Edmonton, Canada. I'm also an anime fan, Gundams lover and gamer. Welcome to my blog.
You can read more about me or follow me on Twitter or any of the following social websites.