Im a bit new to this side of Wordpress and wanted to get some help with the best way to go about this. I created a plugin and what i want it to do is have a simple form with a few fields that will write information to a stylesheet. In this case i have a admin.css file that i enqueued in my themes functions.php file and it works for style changes but it would be easier to have a menu in the backend that will write some info to that file.
how would i go about this and which is the best method?
well this will be done with fwrite function that i think more complex. try to add in simply tags and add_action in to wp_head directoly
Related
Greeting
I have a problem, I would like to create a form on wordpress manually but I cannot attach a php file to my wordpress page.
How to do ?
There are several ways to achieve this.
Create a child-theme from your theme and then create an individual template for the form (https://developer.wordpress.org/themes/advanced-topics/child-themes/). If the form is a page, then just copy the page.php file to the childtheme, renamte ist to page-form.php and then edit it. See https://developer.wordpress.org/themes/template-files-section/page-template-files/ for more information. Afterwards you can change the template in wordpress. Do not forget to sanitize form inputs (https://developer.wordpress.org/themes/theme-security/data-sanitization-escaping/)
Install a form plugin
This is the solution I would prefer if your usecase allows this. I am using wpforms, but I have not checked for alternative plugins the last two years. There may be others that could work for you better.
Create a shortcode for the PHP code, then paste the shortcode on the page where you want to put the form.
Reference:
https://codex.wordpress.org/Shortcode_API
https://developer.wordpress.org/reference/functions/add_shortcode/
I am currently trying to develop a website for fun just to practice. I have written some PHP code locally on my computer together with some css and html. My question is if anyone is familiar with Wordpress? And if so, am I able to import my php files and css into wordpress and use both code and the tools that wordpress has?
Thanks in advance!
Absolutely yes. The first thing you should do is create a child theme.
In it, you will have a style.css file in which you can add all your custom CSS.
Also in there will be a functions.php file. You can add custom PHP in there.
If you're looking to do something more complicated, then look into writing a plugin.
You can create templates on WordPress.
How to create a template
On this template, you can save your PHP.
To add CSS to WordPress you can do that by going to Appearance > Customize > Custom CSS.
The path to your Custom CSS section may be different depending on what theme you use.
I am very new to wordpress. But have good knowledge in php, html, css and javascript.
I want to add custom font-resizer to my wordpress site. as shown below for example.
What would be the best and non-messy way to add the plugin code to my website.
I have looked at some tutorials online but it seems that I can't getting those.
Any help would be appreciated. thank you..
If you're trying to add that plugin specifically to your site, then its documentation suggests:
adding it through a widget that the plugin creates
or using this bit of code wherever you want in whichever template file: <?php if(function_exists('fontResizer_place')) { fontResizer_place(); } ?>
Does your theme have a place for widgets in its header? If not, you'll want to just place that bit of PHP somewhere in your header.php file.
I have currently manually implemented a tracking code in wp-content/themes/genesis/header.php
The code looks like this (shortened):
<script>
CODE HERE
<?php if (is_single()){CODE HERE}?>
CODE HERE
</script>
</head>
Whenever I upgrade genesis (the Wordpress theme) this code is lost and I have to manually add it again.
How can I add this code via the functions.php to the head section in wp-content/themes/genesis/header.php so that it survives a Wordpress theme upgrade - how would the code look?
You need to use wp_head hook to add content to the <head></head> dynamically.
Your code would look like this:
add_action('wp_head', 'change_this_name');
function change_this_name(){
?>
<script>
CODE HERE
<?php if (is_single()){CODE HERE}?>
CODE HERE
</script>
<?php
};
Generally, the solution for modifying your theme without having your modifications overwritten is using a child theme. But you could also create a small plugin that would do the same thing you want to do here.
Which option you take is generally much of a muchness for now, but if you are planning more changes in the future, you should keep in mind that:
plugins are for adding functionality
themes are for controlling how things look and feel
This might help you decide which option is best to take now (although you can easily do both, or change later if you wish :)).
Option 1: Creating a child theme
Create a new folder in the wp-content/themes folder (name it whatever you'd like to call your new theme), and then create a style.css in that folder.
At the top of style.css you'll need to include defining information for your theme. You can copy the format for this from the Genesis theme, just change the name and other details so it's clear when you go to activate it that this is your theme.
The key here is then to add a new line to this theme info reading:
Template: genesis
That line tells Wordpress that your theme will be a child theme of Genesis, and anything your theme doesn't provide, Wordpress will grab from Genesis.
The key here is then to override only what you want to and let the rest fallback to Genesis.
So, you could copy the header.php and add your code in, but then you'll still need to update the rest of the file if it changes. A better solution would be to create your own functions.php in your new child theme and use the following:
add_action('wp_head', function(){
?>
Enter tracking code here...
<?php
});
This will then hook into Wordpress' head action and print out the tracking code right where you want it, without you having to muck around with the rest of the header.
Of course, once you're ready, go to Appearance -> Themes in Wordpress and you'll see your new theme there. Activate it and check your site!
For more background and tips on child themes you can see this page on the Wordpress Codex.
Option 2: Creating a plugin
If it's just functionality you want to add to your site, you may find a plugin more helpful - particularly because you can change themes later and easily keep your plugin, and you can activate it and deactivate it at will.
You can create as many plugins as you like if there is more functionality you want to add later.
The process is fairly similar to creating a theme above. Instead of creating the new folder in the wp-content/themes folder, stick it in wp-content/plugins instead. Then, create a .php file in that folder (eg. myplugin.php, but you can call it whatever you like), and add the following to the top of the file:
<?php
/*
Plugin Name: My Toolset
*/
(You can add additional information if you wish, more information is available on this page of the Wordpress Plugin Handbook)
Under this, simply place the exact same add_action() code mentioned in the theme option above.
Save your file, go to Plugins in your Wordpress admin, find your new plugin in the list, click Activate, and check your site!
For more background and tips on plugins you can see this page on the Wordpress Codex.
i am writing a wordpress plugin and i want to make some changes on appearence of site.How can i change some html and css with my plugin?
What i mean is this:I do something with my plugin and i have some result with that.I want to add some css and make it beautiful.Where i want to make change is home screen.How can i do that?
For example,a theme's div class name is foo,another one is hoo.
Now when i want to prepend something to that div there is no similiarity.So i decided to write a little theme which is integrated to my plugin.
With another word,i want to change theme automatically by my plugin.Is that possible?
You can add new 'CSS' and 'Javascript' in header of you website using
<?php
add_action('wp_head', 'your_function');
?>
In that CSS file you can create whatever CSS classes you want. And yes this can be accomplished using plugin (But not recommended).
You will need to read a little bit about things like:
https://codex.wordpress.org/Writing_a_Plugin
http://www.onextrapixel.com/2009/07/01/how-to-design-and-style-your-wordpress-plugin-admin-panel/
http://wp.tutsplus.com/articles/how-to-include-javascript-and-css-in-your-wordpress-themes-and-plugins/
Good luck and eventually let us know please :)