can we add add_action('admin_init','myfunction') in wp-includes/functions.php - wordpress

I have a question regarding add_action, can i able to add add_action in functions.php that is wp-includes/functions.php
add_action('admin_init','myfunction');

You can, but you should not since all your modifications will be overwritten when you upgrade wordpress. Use your theme's functions.php instead.

Don't put it in wp-includes for the reasons rrikesh states. You're just going to the code on update.
If you have a lot of themes within which you want common functionality, make them children of a parent theme.
The parent can hold all the common code in its own functions.php file and the children will be able to use it.
Review the codex for information on Child Themes and how to implement them.

Related

How is functions.php loaded in Wordpress?

I am starting to study Wordpress a bit deeper and i d like to know which way functions.php file is loaded so that every function is available everywhere in the theme files.
Or at least if you suggest me some source where to find this information.
Thank you
A function.php file:
Executes only when in the currently activated theme's directory.
Applies only to that theme. If the Theme is changed, the functionality is unused.
Requires no unique Header text.
Is stored with each Theme in the Theme's subdirectory in wp-content/themes.
Each theme has its own functions file, but only the functions.php in the active Theme affects how your site publicly displays. If your theme already has a functions file, you can add code to it. If not, you can create a plain-text file named functions.php to add to your theme's directory.
Source # https://codex.wordpress.org/Functions_File_Explained.
In short, the function.php file is a function wrapper. Each function is hooked to a specific action hook. These actions are called when a user opens a page (Server request).
You can get a better understanding of how action hook work by looking at the Plugin API/Action Reference which represent a typical hook firing sequence.

Add comments to wordpress inspect element page

As the title says, I want to add some sort of signature with comments on my wordpress index file, thing is - there are 30 different index files and none of them seems to work
If I understand correctly, it'll just be a case of adding some HTML comments (not PHP comments as they won't show in the source code) in your theme files. Bear in mind that editing a theme won't work if someone else made it and releases updates to it as it'll overwrite your changes if you update it.
The best place to add in the comments is to either open the header.php file and place your HTML comments after the opening <body> tag. If your theme doesn't include a header file, you could always add your comments to the top of your themes index.php file instead.
Your theme should be located within /wp-content/themes/YOUR-THEME/.
Alternatively, you could also place HTML comments between the <head> tags of your theme so they show up a bit higher in the source code. To do this, it's probably best to use an action hook instead. Place this in your themes functions.php file:
add_action( 'wp_head', 'add_signature_to_theme', 1, 0 );
function add_signature_to_theme() {
?><!-- Welcome to my website. --><?php
}
The wp_head action hook documentation is useful to have as reference as well if you'd like a bit more information on what it is and what it does.

How to use wp_dequeue to keep a script from loading in WordPress

The theme author is loading the Google Maps API but it isn't being used on the site so I want to dequeue it in the child theme's functions.php. They don't offer an option to simply disable it within the theme settings.
Would someone mind helping me out with the wp_dequeue code? Also, is it technically more efficient to comment it out in the parent theme or dequeue it in the child theme? I know the inherent problems with modifying the parent theme code, but I doubt the author is going to update this theme in future. Thanks!
wp_enqueue_script('bazien-google-maps', 'https://maps.googleapis.com/maps/api/js?key='.$bazien_theme_options['google_maps_api'], array(), '1.0', FALSE);
If you want to do it the best WordPress way, you'll need to deregister it in the child theme. to do so, use the following :
wp_deregister_script( 'bazien-google-maps' );
It should make the job. To answer the other question, it's more efficient to comment it in the parent theme, because this way you don't load the script to "unload" it after. But, as you truly said, an update might appear somedays, so it's more secure to disable it in the child theme.
See the cod WordPress for more informations aboubt registering scripts and styles : here
and informations about deregistering : here

Require another file before require file functions.php Wordpress

Same as title, i want require file 'foo.php' before wordpress require 'functions.php' in theme. What's solution? Somebody can help me?
Use a Child Theme.
Basically you just do this:
Create a directory in your themes directory to hold the child theme.
The theme directory is wp-content/themes. You should name the
directory without any space as part of the name, and it is common
practice to use the name of the parent theme folder with “-child”
appended to it. For example, if you are making a child of the
twentyfourteen theme, your folder name would be twentyfourteen-child.
Inside, you can create a functions.php and add the code you want, you can even call other files, like your foo.php:
(...) the functions.php of a child theme does not override its counterpart
from the parent. Instead, it is loaded in addition to the parent’s
functions.php. (Specifically, it is loaded right before the parent’s
file.)
You can also create a plugin, they are loaded before functions.php, you can take a look at the loading order here: https://wordpress.stackexchange.com/questions/26537/between-functions-php-widgets-and-plugins-which-is-loaded-first

What makes a Wordpress theme an "invalid parent theme"?

In order to overwrite some CSS of an existing Wordpress theme, I would like to create a child theme of it as described on http://codex.wordpress.org/Child_Themes#Example_of_a_basic_Child_Theme .
I created a directory along with the style.css file, where the parent theme's name is defined as "template". So far, so good. When I go to the themes page in Wordpress' administration, I get the message "The [name of parent theme] theme is not a valid parent theme.", and I cannot activate it.
I am wondering how Wordpress finds out if a parent theme is valid or not and if there is a way to make the parent theme a valid parent theme.
In order to find out if the defined parent theme is the problem, I replaced the "template" definition with another theme, which is also installed on the same server, and that worked.
Thanks in advance for your help.
It seems I forgot to mention the fact that caused the problem: My parent theme is already a child theme, and I was not aware of the two generation limit, which means that a child child theme is not possible. :-(
Thanks for your help anyway! Maybe this information should be added on http://codex.wordpress.org/Child_Themes ...
try checking your child theme's css and look at the #import line and make sure there is a ';' semicolon at the end. :)
Your child theme needs to use exactly the same name (same cases, same spaces etc.) as the parent theme. It's defined as Theme Name in the parent's style.css.

Resources