I am developing a site into sub dirctory-
sitename.com/subdirectory/
I am including an image link from my theme js file.(js/custom.js)
sitename.com/subdirectory/wp-content/uploads/2014/05/333.png
But when i move the site to main directory. I want the sitename.com/subdirectory/ will automatically converted to http://sitename.com/
is that possible? I try to used
/wp-content/uploads/2014/05/333.png
but its not working.
you should do js code in your php script before including script file.
var image1= '<?php echo content_url();?>/uploads/2014/05/333.png';
Then use this variable image1 in your js file.
This will solve your problem.
You can get the current URL by javascript from this Get current URL in web browser
Then check if current URL in subdirectory or not then you can decide what link should to pass to your image link in javascript file
Related
Here is the url in browser i want to change tu.edu.pk/#kingster-moblie-menu to tu.edu.pk/#tu-moblie-menu
Please Hepl me out how to reslove this issue.
You can try this js on your js file
// Replaces the location of the current window with the new one.
window.location.replace("https://www.tu.edu.pk/#tu-moblie-menu");
How to create a new file in my wordpress theme without using ftp client ?
thanks !
Using touch(); PHP function, which creates a new file in the specified directory. This is how I suggest doing it (and admittedly, there are cleaner ways, but this will get the job done, quickly and effectively)…
Open header.php — then write this code in the very top of the file:
<?php touch('wp-content/themes/YOUR_THEME_DIR/FILE_NAME.php');?>
Replace YOUR_THEME_DIR with the directory in which your WordPress theme lives.
Then, replace FILE_NAME with the name of the file you want to create.
Once that’s all done, save Header.php and go to the homepage of your site.
As soon as the homepage loads, it will create that new template or theme file.
Source :
https://www.webmechanix.com/how-to-create-a-new-theme-file-in-wordpress-without-ftp-access/
You can use a plugin called WPIDE found here https://wordpress.org/plugins/wpide/
This plugin will allow you to edit and add folder and files in your project.
I have a slideshow on a php page that uses $folder = opendir($dirpath); to access images in a folder. When I enter the url of said php file all works well, however once I call this php from inside a wordpress page it no longer accesses the image folder.
I'm guessing this is due to the fact the path changes to where the php is being called to. I just can't seem to work out what I need to replace '$dirpath' with so I can access the folder url.
The tag <?php bloginfo('stylesheet_directory'); ?>/imagefolder accesses the folder when not inside a php tag, however I don't know know I can add this inside php tags.
I've tried:
$dirpath = bloginfo('stylesheet_directory')."/imagefolder";
$dirURL = "";
$folder = opendir($dirpath);
but it's not correct.
Any help would be appreciated.
From the documentation on bloginfo:
This always prints a result to the browser. If you need the values for use in PHP, use get_bloginfo().
And checking the docs on get_bloginfo(), you'll see that's better to use get_stylesheet_directory_uri(), so your code would be
$dirpath = get_stylesheet_directory_uri()."/imagefolder";
$folder = opendir($dirpath);
I have just followed a tutorial about creating custom WordPress theme, each and everything went just fine from static to dynamic conversion but when I activate that theme and I come up with a plain HTML document with blue hyperlinks which mean the site is not picking up the css file of style.css
Am I doing something wrong? Please help me.
Check your source HTML and see that the path to your CSS is correct.
You can use bloginfo() to find the correct path by using:
<link rel="stylesheet" href="<?php bloginfo('template_directory'); ?>/style.css">
If your style.css resides in the root folder of your template.
Where did you add the link to the file? - View the source of the page to see if the link is there and try navigating to it to see if it returns a 404 (Not Found) or other error.
My preferred way to include theme stylesheets is adding something like this to my functions.php.
add_action('wp_enqueue_scripts','enqueue_my_styles_scripts');
function enqueue_my_styles_scripts() {
wp_enqueue_style('my-styles',get_stylesheet_directory_uri().'/style.css');
}
Check out wp_enqueue_style and make sure you have a wp_head() call in your header file
I am working on a drupal 7 site and am very new to this. I need to create a totally separate home page from the rest of the site. I notice the head is built in the html.tpl.php file where all the scripts are loaded. I would rather not load scripts to the rest of the site that will only be used on the front page. Also I have found that drupal adds some code to the end of my script rendering it useless.
/js/image_scale.js?lwhgie"
What is going on here and how do get better control of this?
Thanks
Just to add a couple of points:
If you want to aggregate your homepage JS (which you may or may not) then you shouldn't add the stylesheets manually to the template file. You can add them in hook_preprocess_page(), something like this:
/**
* Implements hook_preprocess_page().
*/
function MYMODULE_preprocess_page(&$vars) {
if ($vars['is_front']) {
$path = drupal_get_path('module', 'MYMODULE');
drupal_add_js($path . '/MYMODULE1.js');
drupal_add_js($path . '/MYMODULE2.js');
$vars['scripts'] = drupal_get_js();
}
}
Also I have found that drupal adds some code to the end of my script rendering it useless.
/js/image_scale.js?lwhgie"
That shouldn't render your script useless. From the comments in drupal_get_js():
A dummy query-string is added to filenames, to gain control over
browser-caching. The string changes on every update or full cache
flush, forcing browsers to load a new copy of the files, as the
URL changed. Files that should not be cached (see drupal_add_js())
get time() as query-string instead, to enforce reload on every
page request.
you could create a new template called page--front.tpl.php in your theme folder and this will be your template for the homepage. Now you can add/remove any html markup you want. for more info take a look here: http://drupal.org/node/1089656 . Also, you could "tell" drupal to use your custom template file using hook_preprocess_page() in template.php file in your theme folder. See the comments on the link I posted earlier