I have added two custom written functions to my wordpress code.
One of them uses the add_action() and the other uses the add_filter() function of wordpress.
After deploying the code, both functions work as expected, but after some time (I am not sure how long it takes and what causes wordpress to do so) the code just magically disappears from the file.
I am now wondering
Why is this happening?
What can I do so that this won't happen again?
Thanks for your help
Hey you just mentioned that you've added code into /wp-includes/functions.php file. You've used action and filters that's good but your code should be go into active theme's (child theme is the best practice) functions.php file. Files under /wp-admin/ and /wp-includes/ get updated automatically from WP when new update is available (based on settings you have done on your WP setup you can ignore updates as well).
So, your code must be removed by update. Files were overridden by updates. If you have backup copy those code and put it into active theme's functions.php file /wp-content/themes/yourtheme/functions.php is the correct file where you can add the code.
If you have added code into theme's functions.php file make sure you didn't get theme updated otherwise you may lost your work as well that's the reason you can use the Child theme. You can learn how to create child theme here: https://developer.wordpress.org/themes/advanced-topics/child-themes/
Why is this happening?
Most probably because someone updated WordPress to latest version. Before you are going to tell me "but I did not press anything, ever!" please bear in mind, that WordPress updates itself automatically. Especially in the newer versions.
Here is nice article about WordPress automatic updates. It also describes how to turn this off, but I do not recommend doing so.
What can I do so that this won't happen again?
Develop custom WordPress plugin, containing your customizations. Here is nice step by step tutorial
you shouldn't make any changes into wp-includes and wp-admin folders, these folders will update automatically if your wordpress is updated. so if you want to make any changes using hooks and actions you can place the code into your current theme's functions.php. that will work as expected and your code won't disappear.
Related
I am using X theme from themeco, latest version. Created a custom child theme instead of using the ones made available by them. I followed all of the instructions, the functions.php file loads the activation details of the parent theme, but doesn't include the other functions it needs to load. Like header, footer or any other page, even though all of the files are included in the child theme.
Should I remove them from there and just keep the functions.php and style.css files? I will try that, if it solves the problem, otherwise, the functions are just not being there. Tried to view a test code to see which header was it even displaying, I could see the test text written where the header should be but still can't see the header.
Doing an inspection through chrome I could see lots of problems related to revolution slider, js errors, will need time to debug them but would love if anyone got a quick fix for it without me racking brains all over the place.
Edit:
Code
On wordpress 4.9.1, the plugin Menu Social Icons is installed and the theme Twenty Sixteen is being used. The plugin works as expected, except for Stackoverflow and Vimeo icons. The problem is that for these two websites a generic icon will be shown, instead of the one corresponding to these sites.
In the documentation of the plugin it can be found that this issue is well known and they present the solution. However, due to my lack of php knowledge, I have not been able to make it work.
Their solution:
Option: Add Vimeo and Stack Exchange
To use FontAwesome 4.0+, which drops support for IE7, but adds
vimeo.com and stackexchange.com, add this to your theme’s
functions.php file: add_filter( ‘storm_social_icons_use_latest’,
‘__return_true’ );
I have tried including the line add_filter( ‘storm_social_icons_use_latest’, ‘__return_true’ ); in different locations of the functions.php of my theme, without positive results.
Where would be the correct location to add this line of code in the php file?
In terms of their solution not working, I'd suggest that the issue probably isn't in your functions.php file, as all filter functions in your current functions.php file should work.
A couple of notes to consider though:
If you need to modify a WordPress theme, your best option is to create a "Child Theme" to make the changes in, otherwise your updates will be overwritten whenever your theme is updated.
Also, best practice when working on WordPress themes (or just PHP in general) is usually to add your changes at the bottom of the file you're modifying, after a comment to say what they are, and before the ?>.
A good example in this case would be to modify your functions.php file so it finishes like so:
//function to include latest FontAwesome changes - 31/12/2017
add_filter( 'storm_social_icons_use_latest', '__return_true' );
?>
Although, I can't stress to you how useful child themes are in situations like this.
I need to rewrite some code on my client's website that I haven't made. The problem is that it runs on wordpress (w/ a customised theme I guess) that I've absolutely no experience with whatsoever.
Where do I find the source code made by that previous developer? I tried to find it in the "wp-admin" page but I failed :D ... where would you edit website's landing page?
Thanks ;)
Depending if the developer wrote a new theme or edited another theme, and if the lather, wether he did it the right way.
Check out the name of your current active theme and you should find it here:
/path/to/your/wordpress/installation/wp-content/themes
If he altered another theme, there should be another directory named "activeTheme-child". There any changes should be made so you can run updates on the main theme.
I'm by no means a coder or programmer but i have enough to understand my part and fix small issues or adjust look with basic CSS, and so friend of mine asked me for help and here i am two days later asking you)
There is a Website running Enfold theme which recently were updated and so was lost custom image link at right part of header made by someone-else.
I have restored link code from Cached version of website but have no real understanding how and where to add it back to theme templates. Would appreciate any help, solution, link, advice.
Cheers.
A wild guess, since I don't have Enfold theme (the best would be to ask on the official support), but in your div #header_main in the .inner-container, you had after the #advanced_menu_toggle this piece of code:
<img src="http://vcmt.ca/wp-content/themes/enfold/images/layout/canvas.jpg" alt="canvas" style="max-height:70px;">
Just open the .php file that has the header in it, and paste this code back in. Since the canvas.jpg was located in the /images folder of the theme, that is also gone, so my recommendation is to download the image from the cached version if you can and put it back in the image folder.
Also it would be better to make changes to child theme, so that you can update the functionality of the theme, without loosing any custom added modification, like this site had.
If you're planning on changing the CSS in any WordPress Theme, you want to make sure that you have a child theme installed. The child theme allows you to change/overwrite the CSS and Theme Functions on the theme without losing those changes everytime the theme updates.
You can download the Enfold Child Theme Here:
https://kriesi.at/documentation/enfold/how-to-install-enfold-theme/#why-child-theme
...and if you need to add HTML to the header, you can do so by duplicating the header file from the theme, adding a header file to the child theme, and making your changes in the child theme header file.
Hope this Helps!
I have a working wordpress theme. I don't have any plugins installed in my theme. When I created a new page and wrote PHP code to echo a single line, it does not show anything. I edit the wp_config file and set define('WP_DEBUG', false) to define('WP_DEBUG', true)......but nothing happen, the code is below
<?php
echo 'gggggggggggggg';
?>
When inserting your PHP code into wordpress pages, there are two recommended ways:
make a child theme
write your own plugin
Making a child theme is faily easy and a common way for little PHP extensions.
There is also a plugin available to insert PHP code into pages here.
You should avoid to put PHP files into the internal Wordpress directories or modify wordpress files since these modifications get lost with updates which happen to be quite often in Wordpress
You cannot write PHP in pages directly and its not recommended to do so, because you are opening doors to world of security threats.
The best way to write is, by creating templates(wirte your PHP there) and then assign it to some page.
https://developer.wordpress.org/themes/template-files-section/page-template-files/page-templates/#creating-custom-page-templates-for-global-use