Where do I save widget code for wordpress? - wordpress

I've googled around quite a lot, but can't seem to find where I should be saving the code for the widget I've created. It's a bit baffling.
So, can anyone tell me where I should save my widget?
Thanks,
John.

You need to put your widget code in either the functions.php file of your current theme, or within a plugin. In order to put it in a plugin, create a new folder in the plugins folder and create a .php file with the name of the folder you created within that folder. In that file, use this code to start your plugin:
<?php
/*
Plugin Name: Name Of The Plugin
Plugin URI: http://URI_Of_Page_Describing_Plugin_and_Updates
Description: A brief description of the Plugin.
Version: The Plugin's Version Number, e.g.: 1.0
Author: Name Of The Plugin Author
Author URI: http://URI_Of_The_Plugin_Author
License: A "Slug" license name e.g. GPL2
*/
?>
Obviously, change the values to something useful for your plugin. You can then paste your widget code into this file and it should be ready to use.
Sources:
http://codex.wordpress.org/Writing_a_Plugin
http://codex.wordpress.org/Plugin_API

As far as I know, widget (ie plugins) go in your wp-content/plugins folder eg. wp-content/plugins/YOUR WIDGET/
Is that what you need?

You can save your code in the file of wp-content\themes\YOUR-THEME-NAME\functions.php.

Related

In my theme folder ‘sfwd-lms/includes/shortcodes/ld_course_list.php’ file overwrite not working

I'm trying to overwrite my ld_course_list.php file, but I'm having trouble. I tried to use the same plugin folder structure in my child theme, but it did not display the child theme file content.
Plugin Name: LearnDash LMS
Plugin file location : wp-content/plugins/sfwd-lms/includes/shortcodes/ld_course_list.php
Child theme file location : wp-content/themes/Awake/sfwd-lms/ld_course_list.php
The other two locations were also tried:
(1) wp-content/themes/Awake/sfwd-lms/includes/ld_course_list.php
(2) wp-content/themes/Awake/sfwd-lms/includes/shortcodes/ld_course_list.php
Thanks
Overwriting LearnDash plugin files is not as straight forward as woocommerce, they follow a very different folder structure, try this path:
wp-content/themes/Awake/learndash/shortcodes/ld_course_list.php
or
wp-content/themes/Awake/learndash/ld_course_list.php
Unfortunately there is no proper official documentation on this. Check these articles for more info Article 1 | Article 2

Hook In Wordpress

I modify wp_hash_password and wp_check_password with my own encryption password, I want to use hook now. This is to make sure when my wordpress update the latest version, my wp_hash_password and wp_check_password in pluggable.php still is my own password encryption, the hook should add at where? Look on Internet, some say put in user.php and some say put in function.php in theme. If who know, please tell me the answer.
Plugins are loaded first, then pluggable.php and then lastly the theme. Subsequently, you need to create a plugin and place your pluggable functions code in there otherwise your custom code won't be loaded. Create a file called custom_wp_password_override.php or whatever you want to label it and place it in your plugin's folder adding in your own custom function code. You should never update core files such as user.php as this will be overwritten when you upgrade WordPress.
<?php
/*
Plugin Name: Custom WordPress Passwords
Plugin URI: http://localhost
Description: Override wordpress pluggable password functions.
Version: 1.0.0
Author: Your Name
Author URI: http://locahost
Text Domain: custom-wp-passwords
*/
if ( !function_exists('wp_check_password') ) :
function wp_check_password($password, $hash, $user_id = '') {
// Your custom code in here
}
endif;
if ( !function_exists('wp_hash_password') ) :
function wp_hash_password($password) {
// Your custom code here
}
endif;
?>
So the first thing I know when into WordPress development is not to edit any files in two folders: wp-include and wp-admin. Or you will lose all your edit when update WordPress to the newer version.
Back to your question, if you think you will not change the theme in the future, put your code in child theme's functions.php. Yeah, child theme will not affect when you update your parent theme.
And I think, the best solution for you is creating a simple WordPress plugin, put your code in, and activate that plugin. So your encryption will not lose when you update WordPress core/theme/other plugins even.
<?php
/*
Plugin Name: WP Custom Plugins
Plugin URI: http://link to your plugin homepage
Description: This plugin changes WordPress hashing password encryption.
Version: 1.0
Author: Someone
Author URI: http://link to your website
License: GPL2 etc
License URI: https://link to your plugin license
/* Your code goes below here */

Wordpress Publish Date Shortcode

This sounds like it should be something simple or there should be a simple shortcode plug in to achieve this but i have searched and searched for almost and hour now and can't find the answer. All i am trying to do is display the post's published date in the body text. Example: [meta = "Date"]. Is there an easy light weight solution to achieve this. I simply need to publish the post date inside the content. Thanks.
There is a good article on how to do this with a custom plugin or snippet of code for your theme
https://krogsgard.com/2012/create-a-shortcode-to-show-when-a-post-was-last-updated/
You can create a shortcode easily within WordPress. This is a sample of code that you can either place in a new plugin file. For creating a plugin file, visit https://codex.wordpress.org/Writing_a_Plugin , basically, you create a file, lets say my_shortcodes.php and place it in the /wp-content/plugins/ folder. In that file, you would have the following.
<?php
/*
Plugin Name: My Plugin Stuff
Plugin URI: http://domain.com/
Description: My Plugin Stuff
Version: 0.1.0
Author: Your Name
Author URI: http://your-website.com/
License: GPLv2 or later
*/
function shortcode_post_published_date(){
return get_the_date();
}
add_shortcode( 'post_published', 'shortcode_post_published_date' );
Then you would use the shortcode in your post [post_published]
Disclaimer:
This is a sample of what it may look like. You may have to make some modifications to it to make it work the way you want. You may not be able to copy and paste this into your code and it work right away.

New template not showing up in Template dropdown

I've created a twentyfourteen child theme using the One-click child theme plugin. Then I copied the page.php template from the parent theme folder to the file new-template.php in the child folder. I changed the header in new-template.php to
Template Name: New Template
As far as I know that's all I need to do to get "New Template" to show up in the Template dropdown under Page Attributes when you create a new page. But "New Template" hasn't been added to the dropdown. Does anyone know what the problem might be?
Thank for any help
Just in Wordpress 4.9 there's this bug: https://core.trac.wordpress.org/ticket/42573 causing the template files to only be rescanned once every hour.
To fix (until they release a new WP version with this changed), download the patch on that bug ticket and make the changes from the patch to wp-includes/class-wp-theme.php.
Hope this saves someone the 2 hours I wasted on this..
For the Wordpress 4.9 bug mentioned above, just update the version of your theme in style.css, e.g. from 1.1.2 to 1.1.3 - even 1.1.2-1 will do. This will force updating templates list.
Please make sure You have activated your child theme, if your child theme is already activated then try a different template name.
This worked for me :
<?php /* Template Name: Red Template */ ?>
and a copy of page.php in my theme dir called redpage.php
I also had to log out of the admin and then log back in.
I tried everything and finally did as stol mentioned above. Update the verison of your theme is style.css located in your themes folder. Mine was set to 0.1.3. I updated to 1.1.2 and it worked.
1.active your child theme
2.if you optimze your style.css file add again your first comment such as
/*
Theme Name:
Description:
Author:
Theme URI:
Author URI:
Version:
Template:
License:
License URI:
Text Domain:
Tags:
*/

Override woocommerce files from includes folder

I have directly modified the class-wc-checkout.php file from includes folder in woocommerce plugin to add custom line item meta data. Is there any way to override the class-wc-checkout.php file from my-theme folder as we override template files in woocommerce?
I was having this same issue. I don't have a need for reviews on my site, so I copied what I wanted to remove from a file inside of the includes folder and copied it into my functions.php file like so:
// Remove reviews from WooCommerce
if (! function_exists( 'woocommerce_default_product_tabs')) {
function woocommerce_default_product_tabs($tabs = array()) {
}
}
Works for me!
Only Templates folder files can be override by coping it into your child theme.
For all other files like in includes folder files you can either edit it or use hooks and filters to do so.
I'm not too sure what you are editing for the Woocommerce plugin but yes you can override the woocommerce plugin by adding these hooks and filters to your functions.php file in your theme:
http://docs.woothemes.com/document/hooks/
Example
You need to edit file: /plugins/woocommerce/includes/shortcodes/class-wc-shortcode-products.php
Copy this file to themes/YOURTHEME/inc/class-wc-shortcode-products.php
Add to function.php:
require 'inc/class-wc-shortcode-products.php';
What seems to work for me is to put the file here:
/wp-content/themes/YOURTHEME/includes/class-wc-checkout.php
The difference between the other suggestion and mine is that I don't have the 'woocommerce' folder in the path.
Yes you should be able to do this by uploading to this folder
/wp-content/themes/YOURTHEME/woocommerce/includes/class-wc-checkout.php

Resources