javascript is not running in wordpress - wordpress

I have problem with running javascript codes in may pages.
I tried testing my code in xampp and it was working.
but I can not see them when I add them to my pages or my posts in my host and I installed wordpress again and it wasn't working.
Please help me

There are a few ways you can include JavaScript files in WordPress, I will give you one example using your child theme.
First you need to validate whether or not you actually have a child theme. Use FTP to login to you server and go to the wp-contents/themes directory. There you will see all your installed themes (in your case betheme). If you do not have a child theme follow these steps:
Create a new directory in your themes folder (betheme-child).
Upload your JavaScript file in this directory (for example script.js)
Create a new file called functions.php and add the following code to it: (surrounded by php opening and closing tags):
add_action('wp_enqueue_scripts', 'enqueue_child_scripts');
function enqueue_child_scripts() {
wp_enqueue_script('child-script', get_template_directory_uri() . '/script.js');
}
Login to your wp-admin and navigate to your themes
Enable your child theme instead of your normal theme.
Go to the front-page of your website, look at the page source and check if your JavaScript file is being loaded.

If you are using cloudflare, turn off minify JS.

Related

Cannot add or edit current pages in Wordpress

I keep getting this page whenever I try to edit or add a new page. I cannot do anything to edit my Wordpress pages. My website currently uses WordPress 5.3.2 and it also uses the new Avada theme 6.2. It has been like this all day. What I see when I click to edit through fusion builder or the regular wordpress editor
I can assume that there is an issue with CSS files delivery, it looks like the styles files (css files) are not being opened on your website page.
Possible reasons that might cause this are:
404 error: means all .css files are being called from the wrong URL which might happen if you changed your website URL recently.
You might have moved your website to SSL which changes the http:// to https://.
Possible solutions:
Try to clean your website cache.
Try to access your website using the private session within your browser.
Can you please share your website url?
You can try looking at the browser console to see what error is occurring.
In the recent version of Wordpress this is causing performance errors at its core:
Try adding the line below to your wp.config file below that IF:
/** Absolute path to the WordPress directory. */
if ( !defined('ABSPATH') )
define('ABSPATH', dirname(__FILE__) . '/');
define('CONCATENATE_SCRIPTS', false);
I had an error that did not load JQuery, when clicking on any button to upload files not working. So after I added the last line it worked.

Why does Wordpress Customizer think my theme is broken?

I am creating a Wordpress theme. I have index.php in my theme's root folder. I have my style.css in a separate folder /css. I've got the beginnings of the design done and everything is working fine.
I now want to add some options with Customizer. I've begun to add some in customizer.php. I then go to check what they look like in wp-admin, click "customize" on my theme and get...
"The active theme is broken. Reverting to the default theme."
The theme was working fine up until that point. I've deleted and re-installed it a couple of times now. All is well until I click "customize".
The error message instructs me to check index.php and style.css, both of which are present. Could it be because style.css is not in the root but in /css? If so, how do I get Customizer to recognise this? My stylesheet has been enqueued correctly in functions.php. As I say above, the theme works fine until I get involved with Customizer.
When I click theme details, wp seems to think the theme is a child of itself too. It isn't a child of anything. I am using underscores starter theme and adapting.
What is going on with Customizer and how do I fix it?
The style.css is a stylesheet (CSS) file required for every WordPress theme. It controls the presentation (visual design and layout) of the website pages. In order for WordPress to recognize the set of theme template files as a valid theme, the style.css file needs to be located in the root directory of your theme, not a sub-directory.
There must be connection lost when you update resulting to broken themes or missing files.
You need to reinstall a theme :
There are two ways to install WordPress themes.
Method 1.) Direct Upload inside WP Admin Console
Method 2.) Using an FTP Client
Method 1 is just a matter of uploading the theme from your WordPress admin console.
Once logged in, navigate to Appearance → Themes and click the "Install Themes" tab. Click the "Upload" link and browse to the location where you extracted the package and upload themename.zip.
Method 2 is pretty straightforward.
Using an FTP client is recommended. If the term FTP scares you, don't worry. It's no different than moving files and folders. Filezilla is a free and trusted FTP client.
Extract themename.zip to your local machine
Login via FTP to your web server and navigate to the /wp-content/themes/ folder
Upload the entire themename folder and its contents. Example: /wp-content/themes/yourtheme/
Open your browser, log in to your WP admin section and (in the left column under Appearance) click the Themes link .Click Activate under the theme you just uploaded.

Modifying custom Wordpress pages

Sorry if this question is too basic (It would be great if someone could recommend me on a good resource/tutorial for starting up with wordpress development)
I am new to wordpress development. And I work on a Mac.
I downloaded MAMP, installed wordpress, and installed a custom theme which I bought online.
So far, I've been using the wordpress wp-admin interface to customize the theme.
I created a new Page called "myPage". I'm interested in making some design changes to myPage but the wp-admin tool is limited and I realized I have to start looking/modifying the code.
I'm using Netbeans, and created a new project of my local wordpress folder which contains the wp-admin, wp-content, wp-include folders.
However, I am not sure where in the code to find the page I created "myPage", in order to modify it.
I ran a search on all the code but I don't find any mention of it.
I guess my custom page is saved elsewhere? in the database?
Thanks!
Drill down through wp-content > themes > to your theme's folder. Inside there you will find a file called page.php. That is your default page template. To double check this is the page being used, in your wordpress backend, edit the page and on the right hand side in the 'page attributes' panel, you will see a dropdown under 'Template'. You're purchased theme may have many templates, so that is how you can tell which one is being used.
Note: Creating a page inside of the wordpress backend does not actually create a new page file for that page.
Hope this helps.
Yea, you can find your page in DB, check out link for more info.
To access your database, you need to go to url http://localhost/phpMyAdmin/ if everything is set right; or your local IP/phpMyAdmin/ if host alias is not set.
EDITED
If you are looking for file, you should look in wpfolder/wp-content/themes/some-theme/ and now ether page.php or content-page.php I am not sure.

Wordpress Plugin & Paths

Hey guys I have a plugin and its displaying info on /courses.php (using theme)
How can I get it to display info on /courses/single_course.php
I figured I'd just have to make a /courses/ folder in theme and have single_course.php inside that. However this doesn't seem to work.
I've tried googling but I'm struggling to figure out the keywords to solve this problem! ^_^
OK edit cause nobody is understanding:
I have plugin working. This is a custom plugin
I want to know how to make the following work http://www.example.com/plugin/index.php http://www.example.com/plugin/index.php
Currently to make http://www.example.com/plugin work you just need to create plugin.php in the theme directory and give a callback to a function in the plugin.
Creating /wp-content/theme/themename/plugin/index.php did not work as anticipated.
WP uses specific directories for placing its themes and plugins tom maintain organization standards.
// Pointing to theme WP themes directory
$_SERVER['DOCUMENT_ROOT']."/wp_content/themes/"
// Pointing to theme WP plugins directory
$_SERVER['DOCUMENT_ROOT']."/wp_content/plugins/"
or you can use the built in functions in wordpress
// for themes in any php file after headers
get_template_directory_uri() . '/js/custom_script.js'
// for plugins in you main plugin class
plugins_url('/js/newscript.js', __FILE__);
I would recommend keeping plugins in plugins and themes in themes. What you may be looking for is creating some extra plugin features which will require you to include you extra php functions and classes when the plugin in question is loaded.
First create a folder in under your plugin directory and chmod it with proper web securities
cd /path/to/wordpress/install/wp-content/plugins/your-plugin/
mkdir php
chmod 755
Next either copy or create and edit the new single_courses.php file. I've listed a quick method below if you are creating the new file from scratch. Otherwise just cp it over. In both cases we need to insure proper web access right using chmod.
cd /path/to/wordpress/install/wp-content/plugins/your-plugin/
echo -n "/*Extra Plugin Functions*/" > single_courses.php
chmod 644 single_courses.php
Now we need to be sure to include the new file in our main plugin file
/* Main Plugin File :: ./wp-content/plugins/your-plugin/theplugin.php */
...
include_once $_SERVER['DOCUMENT_ROOT']."/wp_content/plugins/you-plugin/php/single_courses.php"
...
Thats the basic way to go about it. Use the same process for hooking theme php files as well. Always make sure when creating directories and files on your server that proper security is put into effect or you open up your web directory and or server to get hacked.
Hope it helps...
You have to give us more information on what plugin you are using and what you are trying to achieve. The solution may be as simple as pasting a Plugin provided shortcode into the post area of the desired page. Alternatively you may have to edit the plugin itself.

Find the source files of Wordpress

i mean i want to see the source file of the main page.
when i click right click and choice the option view source, so i want to find
the "body" of the file,and edit it physical, which folder can i find it ?
thanks friends.
WordPress's HTML is generated by PHP in conjunction with CSS, so look in your active theme folder in wp-content/themes/yourtheme. You'll find all the parts of a WordPress theme: Using Themes « WordPress Codex.
WordPress runs on the server -- the "source" you're viewing from your browser is client-side, and is essentially the output of the WordPress PHP code that generates the pages (and some CSS transforms). In order to see the PHP source, you'll have to download it from WordPress's website yourself or look at your WP installation directory on your server.

Resources