Hot answers tagged

31

I think you have to be a little careful because it depends on what you are trying to do. If you are using a child theme get_template_directory(); will still go to the parent theme. However get_stylesheet_directory(); will go to the current theme, child or parent. Also, both these functions return absolute server paths. If you wanted a fully formed URI, ...


14

What you're looking for is wp_localize_script function. You use it like this when enqueing script wp_register_script( 'my-script', 'myscript_url' ); wp_enqueue_script( 'my-script' ); $translation_array = array( 'templateUrl' => get_stylesheet_directory_uri() ); //after wp_enqueue_script wp_localize_script( 'my-script', 'object_name', $translation_array ...


13

They should do the same thing, but under certain conditions, may not. First of all note: that the codex entry description is misleading that wp-admin/includes/file.php must be included in context else calling get_home_path() will lead to calling an undefined function. Regarding the codex entry, Description Get the absolute filesystem path to ...


10

Symbolic links are … risky in WordPress. It is easier to use a separate domain for plugins per wp-config.php: define( 'WP_PLUGIN_DIR', '/local/path/to/plugin/directory' ); define( 'WP_PLUGIN_URL', 'http://plugins.dev'); See Strategy On Building Plugin Using Eclipse as an example for IDE configuration with such a setup.


7

You can change the Plugins directory using constants defined in wp-config.php: Set WP_CONTENT_DIR to the full local path of this directory (no trailing slash), e.g. define( 'WP_CONTENT_DIR', $_SERVER['DOCUMENT_ROOT'] . '/blog/wp-content' ); Set WP_CONTENT_URL to the full URI of this directory (no trailing slash), e.g. define( ...


7

The post format taxonomy: The post format is a default taxonomy, registered with: register_taxonomy( 'post_format', 'post', array( 'public' => true, 'hierarchical' => false, 'labels' => array( 'name' => _x( 'Format', 'post format' ), 'singular_name' => _x( 'Format', ...


6

I don't have time to explain this in detail (I shall upon return) but in the meantime this should work for you, Answer updated with explanation as promised. WP Rewrite rules are like voodoo, I'm sure there's more than one way to go about this, but here's mine. Problem: Just to clarify your question for others who may stumble upon this thread, what you ...


6

You can use admin_url() function for wp-admin.css file and ABSPATH for admin.php. $admin_php_path = ABSPATH . '/wp-admin/admin.php'; $admin_css_url = admin_url( 'css/wp-admin.css' );


5

The best way would be to use wp_nav_menu with a custom walker. Prerequisites: Registered theme location Menu saved to that theme location Useage Wherever you want the breadcrumbs (for theme location 'primary'): <?php wp_nav_menu( array( 'container' => 'none', 'theme_location' => 'primary', 'walker'=> new SH_BreadCrumbWalker, ...


5

You need to reference your WordPress template directory when you register the script. Change this: wp_enqueue_script('my_javascript_file', '/javascripts/app.js', array('jquery')); ...to this: wp_enqueue_script('my_javascript_file', get_template_directory_uri() . '/javascripts/app.js', array('jquery')); Codex reference: get_template_directory_uri()


5

The forward slash works on every operating system supported by PHP. Yes, on Windows too. It is also more readable and easier to type, so there is no need to use the constant. See the tickets #20849 and #15598 for related discussion on Trac.


4

These are the following two ways to add theme path in javascript file. 1) You can use wp_localize_script() suggested by wordpress in your functions.php file. This will create a Javascript Object in the header, which will be available to your scripts at runtime. Example : ...


4

You can place the page templates wherever you want (also in a separate folder) as long as the files are within the current or parent theme's directory. UPDATE: Follow this link to get a more detailed information about the Template File Folders: http://codex.wordpress.org/Page_Templates#File_Folders Take also a closer look at the Page Templates and the ...


4

If you just need that class included, and your script is located in the plugin directory, like /wp-content/plugins/pluginName/script.php, then you can do: require realpath('../../../wp-includes/class-phpass.php');


4

The function plugin_dir_path has an misleading name, it doesn't include a file from plugin directory, it just include a file from the same directory of the file passed as argument. When you call include( plugin_dir_path( __FILE__ ) . 'test-plugin/needed_file.php'); from a file in theme directory, you are just trying to include a file from theme directory ...


4

If this is a single WordPress install, there are a couple database entries with your old domain. Specifically, siteurl and home within wp_options. That said, if the dev URL is temporary, you can also set the following two constants in wp-config.php: define('WP_HOME', 'http://' . $_SERVER['SERVER_NAME']); define('WP_SITEURL', WP_HOME . '/'); Provided that ...


3

get_template_directory(); http://codex.wordpress.org/Function_Reference/get_template_directory


3

You need to set the WP_HOME and WP_SITEURL in wp-config.php in a smarter way. Like this: <?php define('WP_HOME', 'http://' . $_SERVER['HTTP_HOST']); // add the next line if you have a subdirectory install define('WP_SITEURL', WP_HOME . '/path/to/wordpress'); This will solve your your issues with site URLs as they will be set dynamically on based on ...


3

Short Answer jquery-ui.widget is one of standard scripts already included and registered in WP. You don't need to register it, just enqueue. In your code what is wrong is the dirname function inside plugin_url. Leave only __FILE__ as second argument of plugins_url Long Answer: More Info jquery-ui.widget is one of standard wordpress scripts so, in most ...


2

With WordPress 3.4 was a change that allowed you to place your custom page templates in a subdirectory of your choice. The subdirectory can be named anything you want, but it needs to be in your active theme's main folder.


2

Always use the built-in versions. Don’t waste time with old WordPress installations – other plugins will break there too. See wp-includes/script-loader.php for the list of available files. Quite a lot. :) And avoid remote resources. Some (Google) fail to send the scripts gzip compressed to all supporting browsers, others may not be reliable enough. There ...


2

There's a few plugins to fix this, but basically it your database still references the images to be "oldsite.com/wp-content/uploads/" and you need it to be "newsite.com/wp-content/uploads" So you have to change all old references. You could use SQL: UPDATE wp_options SET option_value = replace(option_value, ‘http://www.oldsite.com’, ...


2

get_stylesheet_directory_uri() is a PHP function, you must use it in a PHP file instead of your CSS file. In your functions.php you can paste this code and change depends on your needs: function my_login_logo() { ?> <style type="text/css"> body.login div#login h1 a { background-image: url(<?php echo ...


2

You will want to run a find-and-replace script across the database to update all URLs to reflect the new domain. Just because you change the WordPress settings doesn't mean the content stored in the database has been updated with the new domain! I've had good luck with the Velvet Blues Update URLs plugin but you can also do this type of find and replace ...


2

There's no need for the wp-content/themes path - both themes sit in the same directory, so you can just traverse up one and then back down to child theme: background-image: url(../child-theme-name/images/some-image.png); Update: Regarding your answer to "where is the CSS file stored", you inferred that the stylesheet resides in the child theme folder - in ...


1

I don't know what "wp vip" wants or needs, but you should be loading files by means of get_template_part, locate_template, site_url, or home_url and I am guessing that using one or more of those is what the "scan" wants. It is hard to say exactly which since you posted only the error and not the source that goes with the error.


1

WordPress would allow this (sort of). You would still need to create an About page in the back end, but you can tailor your display for such a page 2 different ways: Page Templates Page template hierarchy - What this means is there is a certain order of what WordPress is looking for when displaying any page/post. Check out the image here for a more direct ...


1

You can localize your javascript files, wich gives you the opportunity to generate a javascript array filled with PHP defined values (such as localisation or directories). If you load your javascript file trough wp_enqueue_script or wp_register_script its easy to set up like follows: function localize_vars() { return array( ...


1

Call get_stylesheet_directory_uri() for the current theme, or get_template_directory_uri() for the parent theme of a child theme, and append your file paths to that. $url = get_stylesheet_directory_uri() . '/images/my-icon.png'; $url = get_template_directory_uri() . '/images/my-icon.png'; Edit: To determine whether you're in a plugin, a parent theme or a ...


1

If I understand you, don't use 'localhost'. That only works if you are testing from the same machine that is running the server. (A virtualized machine counts as a different machine.) Give your server (the machine running the server) a static IP address-- something like 192.168.1.5-- and use that instead of 'localhost'. That will work for any machine on your ...



Only top voted, non community-wiki answers of a minimum length are eligible