Quick tip: paths and URLs in WordPress

The direct reason for this was one of their code examples and the authors apparent incomplete knowledge of the WordPressAPI‘s most basic functions and constants. In that example, he does the following:

define(

‘MY_WORDPRESS_FOLDER’,

$_SERVER[‘DOCUMENT_ROOT’]

);

define(

‘MY_THEME_FOLDER’,

str_replace(“”,’/’,dirname(__FILE__))

);

define(

‘MY_THEME_PATH’,

‘/’ . substr(

MY_THEME_FOLDER,

stripos(MY_THEME_FOLDER,’wp-content’)

That annoyed me, quite a bit. Why? Well because if people write articles about stuff like custom write panels, I expect them to know a bit about the basics of the WordPress API. And well, the WordPress API has constants and functions for these things. So let me introduce you to them in the same order as the author of the articles did his defines above:

ABSPATH constant

Not only is their method inconvenient, it’s wrong for a lot of installs. You see, some people install WordPress in a subdirectory, and depending on what you need, there are two different paths you might need. ABSPATH is a constant that always returns the home of WordPress. So if WordPress is in the wp/ subdirectory, it would give you something like: /home/username/public_html/wp/. If WordPress were installed in the root, it would just return /home/username/public_html/. Now I don’t know how they’re using it, as it’s not used in this particular article, but they’d have to be very cautious with that.

TEMPLATEPATH constant

The second two things they’re doing are possibly even weirder. First they define a constant MY_THEME_FOLDER, which is basically the path to the current theme. WordPress has a very convenient constant for that: TEMPLATEPATH. Since they’re using it in an include, that’s probably what they need. Would save about 4 lines of code. Note that what they call a “folder” is actually a path.

get_template_directory_uri()

This is were they really go wrong. You see, they define a constant MY_THEME_PATH, and then use it as a URL in a call to wp_enqueue_style(), in other words: to enqueue a style sheet. Now paths and URLs are different animals altogether, and they don’t mix well. Take this example:

1 My blog is installed in a subdirectory /wp/

2 Because of that MY_THEME_FOLDER has been defined as follows:

/home/user/public_html/wp/wp-content/themes/example-theme

3 The code that sets MY_THEME_PATH turns that into:

/wp-content/themes/example-theme

4 The stylesheet is now included with the following path:

/wp-content/themes/example-theme/custom/book_panel.css

5 This causes a 404 (file not found error) because that directory simply doesn’t exist! It should have been:

/wp/wp-content/themes/example-theme/custom/book_panel.css

The proper way of doing the enqueue would thus have been the following:

wp_enqueue_style(

‘my_meta_css’,

get_template_directory_uri(). ‘/custom/book_panel.css’

);

Conclusion

I hope you understand why this annoys me. This is exactly the kind of coding that gives WordPress coders out there a bad name, as 5 – 10% of people out there trying this will not get it to work. If you want to prevent from making such mistakes, there’s plenty of resources to learn about these things, or look them up. Two starting points would be the codex and my own cross reference of the WordPress source along with its very convenient WordPress source search function.

Let’s pick up where we left off, and talk more about Drip Marketing. But this time, more specifically about how you can set up truly effective email drip campaigns. In the last post, we discussed at length about what exactly drip marketing entails and several examples to inspire your own nurturing campaigns. But as Frank Herbert... [Read More]The post 5 Step […]

Amit was having an exceptionally bad day. No lead seemed interested in his product, despite calling dozens of them. He had been a sales guy for over 3 years, he knew that he wasn’t giving them a wrong pitch – the leads, just weren’t right. Exactly one floor above, Namrata – the marketing head wasn’t... [Read More]The post 5 Ways How Marketing Automation Soft […]

Does this ever happen between your sales and marketing teams? Marketers spend a lot of time, effort and money to create compelling campaigns, optimize them to generate leads, set auto-responders and alerts to connect with them promptly, before finally delivering the leads to the sales team. Many sales people do not even know these terms, but they very... [Re […]

A few months ago, we conducted a webinar on Google Adwords. After the session, questions poured in. Among all the questions about keyword match types, conversion rates and campaign structure, there was one question that kept appearing – how to increase CTR in Google Adwords? It’s a fair question, but before we get to that, there’s one thing... [Read More]The […]

It is a farmer’s delight to see the seeds he has sown bear fruit. But ask a farmer, it’s not that straightforward. While too much water may spoil the crops, too little would cause them to wither. The farmer has to ensure that the crops get an adequate amount of water at the right time. And... [Read More]The post 9 Creative Drip Marketing Ideas to Boost Your […]

It wasn’t very long ago that salespeople used pen and paper to note down the sales enquiries, scribbling down the details of prospective buyers. After a while, computers took over and digital notepads replaced paper, which were finally replaced by web forms. To state the obvious, this means that businesses don’t need to note down the information anymore –... […]

Last time AdNabu‘s Salil joined us for a Google Adwords tutorial session, he shared quite a few PPC tips that Adwords beginners can use. You can check out the recording here, and the questions asked during the session here. This time around, we wanted him to discuss things that are a little more advanced, and the session was a... [Read More]The post Google A […]

We were expecting breaking news on the American Elections. We sure as hell did not expect this – Our beloved PM Narendra Modiji announcing the demonetization of the 500 and 1000 Rupee notes The impact it had was definitely BIG. It set the Twitteratis in a frenzy, with constant tweets, hilarious memes and endless opinions.... [Read More]The post 6 Real-time M […]

Marketing involves a lot of ambiguous activities, and hence might just be the most misunderstood function in the business! Do you feel my pain? As marketers, we are always struggling to find metrics beyond the superficial vanity ones (likes, shares and traffic) to show for our efforts. In addition, constant experimentation and monitoring is also... [Read Mor […]

Media coverage can be hard to come by even for long-established companies, but it’s significantly harder for startups. Hacking the Media: How to Get Media Coverage for Your Travel Startup In our last webinar, travel marketing expert, Tanu Arora from TravHQ – a travel marketing and media website, joined us to discuss, how to get media coverage... [Read More]T […]

#Chennai was washed away and everything stood still...This had never happened before... nobody was prepared for this.My child and I were alone and with no electricity and dead phone lines...I could not reach out to loved ones and they could not reach me...What in the world was happening??Totally cut off from civilisation...Life was in animated suspension for […]

Today I hold my child a little closerMy kiss lingers a little longerI laugh at his jokes a little harder Appreciate his handmade birthday card a little louder...I'm scared... Scared for my child's futureWhy should anyone be a victim of terrorWhy should so many innocent suffer?Why can't the killers be the ones in the coffer?My tears don't […]

My latest release from the film 'ISAI' Composed and Directed by Mr.S.J.Surya. A kuthu song with english lyrics penned by moi... so excited to have had the opportunity to sing and write such a fun filled peppy number. Hope you all like it!

Picture taken at the event celebrating '100 years of Cinema' at Nehru Indoor Stadium. I had the opportunity of taking a pic with the great legend Mr.Yesudas, Sriniji and Manoji.- Posted using BlogPress from my iPadLocation:Nehru Indoor Stadium

Many years ago... I would look at an office goer/ 9-5 er and think... they are so lucky... why you wonder...well... lets go back to when I was 5. It started out as a mere song to be sung on stage, but evolved into a mammoth production were I was required to sing and dance holding the worlds biggest heaviest mic(I wish I had a pic) with a choir of 30 being sh […]

There are so many things happening around us... new ventures, new inventions,new discoveries.... there is so much to know... on one hand you discover that there are these new #google cars that dont need a driver... and that is instantly stale news when they come out with the new google glass! Felix Baumgartner jumps off the edge of space and an adrenaline ju […]