I would like to override/update to core shortcodes.php file. Build an array and send data differently to other functions, but my question is how to do that without editing the core file? Is there a best practice way overriding core files and/or functions?

  • Can you give us an example of a shortcode you want to override and what you want to override it with?
    – EAMann
    May 22 '13 at 15:59

You can't "override" whole files or functions, except in special circumstances. That is basic PHP.

WordPress has code in place that will let you override particular files and functions. For example, child themes can override parent theme files. That is because of the way the WordPress Template loader works. The override only works if the files load via that mechanism. Those files are meant to be overridden. Core files are not.

WordPress also has a number of functions in pluggable.php that are wrapped in a if ( !function_exists('some_function_name') ) : conditional. If you declare a function with an identical name before that file loads, then your function will be used and not the default. Again, those are meant to be overridden.

And some hooks let you replace callback functions.

Otherwise you can't override files and functions. You need to find another way to do what you want. Maybe that involves hooks, but you will need to did through the source to find the hooks you need.

For shortcodes in particular, you can remove shortcodes individually with remove_shortcode, and then replace them with your own but you can also clobber/hijack another shortcode just by registering another one with the same "tag".

Proof of concept:

function test_sc($atts,$content) {
  return 'Howdy';

function clobber_test_sc($atts,$content) {
  return 'Hi';

However, shortcodes.php doesn't actually contain shortcodes. It contains the shortcode support functions-- the API. Those are not meant to be meddled with, and there are no hooks that I spotted.

As far as "Build an array and send data differently to other functions", I don't even know what that means but my guess would be that you can't do it.


Hooks are a way to override core files


Write your own Shortcode and remove default one.

shortcodes.php is a simple set of functions for creating macro codes for use in post/page content. like [gallery]

  • Which hook covers my problem? Because I didn't found anything useful in that list. May 22 '13 at 13:52
  • Like wordpress default widget text-widget, it not execute shortcodes.but wordpress provide filter by which we can alter its's behaviour and force it to execute shortcode( for ex. add_filter('widget_text', 'do_shortcode');) read this , dig into wordpress shortcode.php or wordpress codex to find for hook for your shortcode May 22 '13 at 14:00
  • Thank you. And if I write a function in functions.php how can be called to shortcodes.php functions? May 22 '13 at 14:14
  • Read more about wordpress hooks.when wordpress execute a shortcode, It also execute action and filter on it. and then return a final output.wordpress take care of all code in functions.php. May 22 '13 at 14:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.