Archived topic
Using "Simple PHP" plugin generates errors
7 replies · Started by Anonymous on July 10, 2016
I found the article in the knowledge base about adding PHP. I downloaded the Simple PHP plugin, and added
echo "This is our custom template!";
I tried it with and without a closing ?>
This is what I get now:
This is our custom template!
Warning: Cannot modify header information - headers already sent by (output started at /home/bsa566/public_html/wp-content/plugins/generate-simple-php/custom.php:8) in /home/bsa566/public_html/wp-content/plugins/wpclef/includes/lib/wp-session/class-wp-session.php on line 130
Warning: Cannot modify header information - headers already sent by (output started at /home/bsa566/public_html/wp-content/plugins/generate-simple-php/custom.php:8) in /home/bsa566/public_html/wp-content/plugins/custom-database-tables/lib/webapis.php on line 131
Warning: Cannot modify header information - headers already sent by (output started at /home/bsa566/public_html/wp-content/plugins/generate-simple-php/custom.php:8) in /home/bsa566/public_html/wp-content/plugins/custom-database-tables/lib/webapis.php on line 132
Warning: Cannot modify header information - headers already sent by (output started at /home/bsa566/public_html/wp-content/plugins/generate-simple-php/custom.php:8) in /home/bsa566/public_html/wp-content/plugins/custom-database-tables/lib/webapis.php on line 133
Also, I am a little confused. I want to write some custom PHP (custom database table access) on just a subset of the pages, not all of them -- is this the right way to do it?
Can you paste the entire contents of your simple PHP code into a pastebin and show me?: http://pastebin.com/
Looks like there might be an error in there.
I have pasted it to <http://pastebin.com/Fd0ESh8M>
Not seeing anything wrong with it, but it just might be that you're echoing code which can interfere with other code.
Try this instead:
add_action( 'generate_before_header','generate_test_function' );
function generate_test_function()
{
echo 'This is a test.';
}
OK - I tried that and I don't get any errors now. Thanks!
However, if I call that method (generate_test_function()) I get the same problem. It looks like it's because the script code is injected PRIOR to the <html> tag (see below). That seems bad, but not fatal. Assuming it's okay, this brings up my other question. I can define functions here, but how do I call them (and only on some pages, not all of them)? Calling them in the simple PHP causes an error. In my use case, I want to provide a search UI against some custom database tables, but only for certain pages, not all.
Thanks.
--Nik
-----------
This is a test.<br />
<b>Warning</b>: Cannot modify header information - headers already sent by (output started at /home/bsa566/public_html/wp-content/plugins/generate-simple-php/custom.php:11) in <b>/home/bsa566/public_html/wp-content/plugins/wpclef/includes/lib/wp-session/class-wp-session.php</b> on line <b>130</b><br />
<!DOCTYPE html>
<!--[if IE 8]>
<html xmlns="http://www.w3.org/1999/xhtml" class="ie8 wp-toolbar" lang="en">
<![endif]-->
<!--[if !(IE 8) ]><!-->
<html xmlns="http://www.w3.org/1999/xhtml" class="wp-toolbar" lang="en">
<!--<![endif]-->
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Edit Plugins ‹ — WordPress</title>
<script type="text/javascript">
Calling a function directly in that file will cause errors, as that file is for defining functions, or hooking them into the template.
If you define a function in there, you need to then call that function inside a template file, inside a function which hooks it into the template (my example), or in GP Hooks.
Hope this helps :)
A few questions. The answer may be the same for both :-)
1) I find that some of my HTML that I put into PHP is being ignored when in Generate Press pages. For example, table borders are always present, the align attribute is ignored, as is colspan for a TD. They work fine if I just make plain HTML and open it in the same browser. How can I get those to work again?
2) I have an IFRAME that runs some PHP code. Though I've turned off all the page attributes, like footer, sidebar, etc., I still get a thick gray background color at the bottom and the page contents are inset. Is there a way to have GP just show a page without any "GP stuff"? I need access to Wordpress database calls so it can't be a vanilla PHP somewhere random.
Hi there,
1. This will remove the borders: https://generatepress.com/forums/topic/table-boarders/#post-129050
The align attribute should be replaced with CSS.
You can remove all of GP's styling of borders with this CSS:
table {
border-collapse: initial;
border-spacing: initial;
border-width: initial;
}
table, td, th {
border: initial;
}
2. Can you link me to the page so I can see?
