Create a form on wordpress - php

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/

Related

Default text appears on wordpress

Actually i'm working on a wordpress website, which is related to school, i'm using universh WP theme which is purchased. I'm getting the below text as default:
Want create site? Find Free WordPress Themes and plugins.
See, i've marked those words. Actually its a dynamic page, i've checked the core code. It's only the
the_excerpt()
function. After that i don't have any idea, where it comes from. Also i've read this thread So please don't recommend that thread, its not working i've tried the way there mentioned.
P.S. Also the text will disappears when I login and try to edit the page.
What text editor You use ? Most easy way will be open folder with theme in some editor and search this string "Want create site? Find Free WordPress Themes and plugins." in all files - then You will know where they add it ... or You can check every file, because this string must be included somewhere, maybe in function.php they add some modification to the_excerpt();
I think when you ass content in post default editor then is not showing in the_expert() function
So you can add content in expert editor then after call the_expert() funtion
Check that your theme is not using the get_the_excerpt filter to prepend that phrase to all the excerpts.
Additional, if you only checked the files that load for that specific template, I would recommend that you run a search for that string for the entire theme. The source of the issue might stem from functions.php or even some JavaScript file.
Please update the core files or update version of your WordPress. Use Latest one.

How to add custom div (+php) code to wordpress site

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.

Wordpress - creating custom pages with php code

I need to add few additional pages to my wordpress site.
These pages should not be "part of the site", ie they should not be linked somewhere from the posts and so on.
However, they should have the same header/footer as the rest of the site ( I am using custom theme ). And they should be accessible via url.
The final requirement is, I should be able to code in php.
At the moment, I tried to create a new "Page" in my admin console. And then write some php-code inside. However, all my php code gets commented and since not executed.
I don't think that installing plugins such as Exec-PHP is a good idea, so I am trying to find other solutions.
Any comments/advice/suggestions how to make it?
I would be grateful if you give me some how-to link.
Thank you in advance.
You can use a custom page template in your theme for this and just keep the site empty in the admin panel:
http://codex.wordpress.org/Theme_Development#Custom_Page_Templates
By using Template tag's you can create custom page.
write this code on the top of your php file....
/*
Template Name: Your Template Name
*/

How to save PHP code written in Wordpress page

I'm using Artisteer to create WordPress themes.
Artisteer is not able to include php code into pages, then I have to do some modification via WordPress page editor.
I'm using "PHP Insert" plugin to include php code into WordPress page editor and to make WordPress able to use my php code into my pages.
In my site I have a form for B.M.I. calculation and I need to use php code in the page.
The problem is that if I change the theme in Artisteer and if I upload it into WordPress, I loose php changes.
It's very boring to apply modification every time (and also dangerous...lost code, wrong code position,...).
I'm thinking to use a child theme, but I don't know how to apply it to php code added into pages.
Suggestions?
Thanks in advance
The Wordpress team has made it a rule of thumb to never execute PHP in posts and pages either because it can be hectic to change things in the future and may expose security vulnerabilities that could not be fixed by Wordpress itself.
A better practice is editing your WordPress theme by creating a custom post/page template - that basically can include everything. However for some situations, it may be necessary to execute PHP on more than one WordPress posts/pages.
In this case, my recommendation would be to create a simple page template containing your PHP, or, if your code is used multiple times, create a shortcode (in the functions.php of your template).
Simplest example of adding a shortcode tag (with parameters) to your themes functions.php:
function footag_func( $atts ) {
return "foo = {$atts['foo']}";
}
add_shortcode('footag', 'footag_func');
The output code can be used everywhere with the tag [footag foo="bar"]. When extending this, alway remember to return the results of your function. Using echo or print would just echo the results (on the top of your content, skipping the content itself).
You're not supposed to use PHP in the content editor, you've got a few decent options:
Creating a custom template for that specific page:
http://codex.wordpress.org/Page_Templates
Creating a shortcode for that specific piece of PHP code:
http://codex.wordpress.org/Shortcode_API

Wordpress plugin using existing theme

I am building a plugin for the first time and I have setup my rewrite rules to call a PHP file I have located in my plugin folder and this is working but all I have it output just now is "test"
I wanted to ask, is there is a way of pulling in the existing theme and using this as the basis for the page, then I can have my plugin just output the page content area so to speak.
My plugin is quite big in terms of the amount of data it handles so I would like to be able to use a menu link to the aforementioned file and this file can then output all the sub pages of content but still using the default theme (theme I have made) and fill the content area only is this possible and if so is there anything to explain this already available because I couldn't see it.
Any help with this would be much appreciated.
Edit: I have tried including a file from my current theme but this will give me a 500 error so I assume its not as simple as this.
Have you thought about using custom post types for your plugin content rather than relying on custom tables and separate code?
Other than that, you could use a shortcode (just one) and have users insert that into a regular WP page, the shortcode then displays all of your various plugin stuff.
It's hard to be more specific without understanding why you've done it this way.

Categories