WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a plugin I'm developing. It works fine on a single site version of WordPress. It installs on a multisite version of WordPress, it appears to work on the admin pages, but when the plugin attempts to add javascript and css, it's not added.

The display portion of the code is as follows...

   add_action('init', array(&$this, 'init'));

   function init() {
        // Gather gallery and template variables
        $url = explode('?', 'http://' . $_SERVER["HTTP_HOST"] . $_SERVER["REQUEST_URI"]);
        $ID = url_to_postid($url[0]);
        load_plugin_textdomain('ngTemplateCreator', ngTemplateCreator_DIR . '/lang', basename(dirname(__FILE__)) . '/lang');
        $t = get_post($ID);
        $c = 0;
        $regex_pattern = get_shortcode_regex();
        preg_match_all('/' . $regex_pattern . '/s', $t->post_content, $regex_matches);

        // loop thru shortcode
        foreach ($regex_matches[3] as $key => $value) {
            if ($regex_matches[2][$key] == 'nggtc') {
                $c = $c + 1;
                //  Found a NextGEN gallery find out what ID
                //  Turn the attributes into a URL parm string
                $attribureStr = str_replace(" ", "&", trim($value));
                $attribureStr = str_replace('"', '', $attribureStr);

                //  Parse the attributes
                $defaults = array(
                    'id' => 0,
                    'template' => ''
                $attributes = wp_parse_args($attribureStr, $defaults);

                if (isset($attributes["id"])) {
                    $this->gid = $attributes["id"];
                if (isset($attributes["template"])) {
                    $this->tcname = $attributes["template"];

                $wrapper = "nggtc_gallery_" . $this->gid . "_" . $c;

                if (!empty($this->gid) && !empty($this->tcname)) {
                    $images = get_ngg_gallery($this->gid);
                    $templates = get_custom_template($this->tcname);

                    if ($templates && $images) {
                        foreach ($templates as $template) {
                            if ($template->bottom_javascript) {
                                $this->bottom_javascript = $this->bottom_javascript . process_script_shortcode($template->bottom_javascript, $wrapper, $panelid, $panelcss, $filmstripid, $filmstripcss) . "\r\n\r\n";
        $this->count = $c;
        if ($this->bottom_javascript) {
            add_action('wp_footer', array(&$this, 'footerScripts'), 200);

    function process_script_shortcode($script, $wrapper, $panelid, $panelcss, $filmstripid, $filmstripcss) {
        $out = remove_php($script);

        // Swap shortcode
        if($out) {
            // strip html from filmstrip variables
            $filmstripi = str_replace(" id=\"", "", $filmstripid);
            $filmstrip = str_replace("\"", "", $filmstripi);
            $filmstripcs = str_replace(" class=\"", "", $filmstripcss);
            $filmstripc = str_replace("\"", "", $filmstripcs);
            $out = str_replace("[wrapper]", $wrapper, $out);
            $out = str_replace("[panel_id]", $panelid, $out);
            $out = str_replace("[panel_css]", $panelcss, $out);
            $out = str_replace("[filmstrip_id]", $filmstrip, $out);
            $out = str_replace("[filmstrip_css]", $filmstripc, $out);
        return $out;

    function footerScripts() {
        if (wp_script_is('jquery', 'done')) {
            echo "<script type=\"text/javascript\" defer=\"defer\">" . $this->bottom_javascript . "</script>";

I'm only showing the function for my footer scripts, but none of the scripts and css are being shown, so I'm fairly certain the source of the error is the same.

Can anyone tell me where I'm going wrong here?

share|improve this question
Ok, in my debugging I did find this... $ID = url_to_postid($url[0]); results in a 0, which is an error. Can anyone tell me how to get the post ID for a mutlisite page? – Kevin Burnett Jan 25 '13 at 3:35
is there a reason you're just not just using the global $post variable? is_single() might also be needed depending on what you're trying to do. – Evan May 3 '14 at 17:26

As @Even commented, instead of url_to_postid(), you should be using something like this:

if ( ! is_single() ) {

$post = get_post();

url_to_postid() is a round-about way of getting the ID of the current post, when WordPress has already determined what the current post is, i.e., it has already parsed the URL to get the post ID.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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