Wordpress template url path
Active Oldest Votes. Lance Cleveland There are other situations where you would not have already loaded WordPress, such as if you have a dynamically-generated javascript or css file that needs to find the location of wp-load. Mahmood Rehman 4, 7 7 gold badges 37 37 silver badges 73 73 bronze badges. Jaya Kuma Jaya Kuma 5 5 silver badges 2 2 bronze badges. I agree! Simple and objective. This is the correct answer. This only works if your file is already running within the WordPress context. Omry Yadan Omry Yadan Note that wp-config.
Using wp-load. No no no! How can that be an accepted answer? Not only the OP didn't mention about his code being in a plugin, but relying on such a frail code should always be avoided. Wordpress structure may evolve. If you really need to know Wordpress' root dir, maybe there's a conception mistake. Try top store your file somewhere else that will be at a known relative path from the file you're loading it from.
For prior versions, just check the code of wp-load. Show 9 more comments. Sisir 2, 5 5 gold badges 42 42 silver badges 71 71 bronze badges. Naty Naty 5 5 silver badges 6 6 bronze badges. That assumes the templates are until wp-content, which may not be the case.
That can be done when WordPress loaded its environment, e. Improve this answer. Community Bot 1. Thanks for your answer. I can not get the above code to work. That value depends on your real url. Keat — gmazzap. Thanks for the reply, and sorry for the late answer. I used this solution and it works perfect. Dan U. In your WordPress theme you can create a page template and rename it to page-id. Shivanand Sharma Shivanand Sharma 2 2 silver badges 7 7 bronze badges. So, Let's open the new page 'mysite.
Jose Velandia Jose Velandia 1. Sign up or log in Sign up using Google. Sign up using Facebook. Why do I want to do this? I recently had a customer asking to get the average rating for a particular post, so they could display it in a banner on another site via an iFrame.
There are other ways to achieve this, but the simplest is to use the URL Parameter and post template combination to serve up just the average rating, as follows:. This function checks if the URL parameter is set line 3 and, if so, returns the path to the single-basic. Disclaimer: The above code will fail if the single-basic. Switch themes and this will break anyway, unless you recreate the template in the new theme. In your theme folder you need to create a file called single-basic.
Whatever you want to tweak the post. Note: this just creates part of the page. If you need to have a full HTML page, simply add the tags to single-basic.
You can probably get the basic code from your header. You could even link to a custom CSS file if you just want to make style changes, although there is a better way to do that without using custom post templates. This technique could cause duplicate content in the eyes of the search engines.
Doesnt work for me. Works for css but not for image. So how are you doing it? Show 1 more comment. Gediminas 6, 6 6 gold badges 41 41 silver badges 56 56 bronze badges. Allen Allen 1 1 silver badge 2 2 bronze badges. This example will not work, if you are using a child theme.
Hitesh Sahu Hitesh Sahu I had to use Stylesheet directory to work for me. Ian Ian 2 2 silver badges 11 11 bronze badges. You probably use a child theme. But your answer should be the accepted one by now. This was the only one that worked for me when using a child theme — jleggio.
0コメント