Tag Info

Hot answers tagged

13

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 ...


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.


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.


5

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 ...


5

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( ...


5

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 ...


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 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, ...


3

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


3

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' );


2

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 : ...


2

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 ...


2

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 ...


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

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 ...


2

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

If this is a single WordPress install, there are a couple database entries with your old domain. Specifically, siteurl and home within wp_posts. 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 ...


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 ...


1

Go to Settings > Permalinks and insert archive in the Category base field. For custom post type archives, you can set that to anything you want via the has_archive argument of register_post_type: 'has_archive' => 'archive/your-post-type'


1

The answer is to use wp_register_style() and wp_enqueue_style() before I do wp_register_script() and wp_enqueue_script() so that I can use relative image paths to the CSS file. I then move the url() stuff from jQuery and into the CSS file with this relative path.


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 ...


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

$.get('<?php echo get_bloginfo('template_url')?>/includes/func.php', {


1

It is an constant, only a string. For the separator / have PHP an constant. Also, this is WordPress, differently are stupid ;-)


1

Try changing the WP_CONTENT_DIR path in wp-config.php Try adding: define( 'WP_CONTENT_DIR', 192.168.X.X . '/blog/wp-content' ); http://codex.wordpress.org/Editing_wp-config.php#Moving_wp-content


1

I think you should run a custom mySQL query to the wp_posts table, something like - SELECT ID FROM `wp_posts` where guid like '%filename.jpg'; (of course use $wpdb object to query the databse). Then you will have the postid of that attachment file and you can use wp_get_attachment_url() from the WP API.


1

wp_upload_dir() is perfect. It is the only place where you can expect write permissions. Store the attachment ID, not a path. Then you get the image with: wp_get_attachment_url( $attach_id ) Sometimes a user may have deleted the image per media library. To avoid problems with missing files check the return value from wp_get_attachment_url() first. ...


1

Something like this should do it, you may have to fiddle with the preg_replace() to get it to work the way you need, but the concept (and, more importantly imo, the regex, is there). if( is_single() ) { add_filter( 'the_content', 'wpse44503_filter_content' ); } function wpse44503_filter_content( $content ) { $regex = '#src=("|\')'. ...


1

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’, ...



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