WillBontrager
Forum Replies Created
-
Hi nirgalo,
It should work.
Verify the included and required files are accessible and contain no errors.
If still no joy, post the code that doesn’t work, (including the [insert_php] and [/insert_php] tags). I’ll see what I can see.
Will
Hi grimerking,
It’s a common misconception and I’ll have to rewrite the instructions page to make it clearer.
While Inert PHP is a plugin, it runs only PHP code that would run on a page independent of WordPress. In other words, it doesn’t have access to WordPress-specific functions.
Thus, neither get_post() nor apply_filters() will run within Insert PHP.
An independent MySQL connection with PHP mysqli…() functions to retrieve the content of certain tables should work. You may need to write your own filter function as a substitute to apply_filters().
Putting the PHP code into a separate web page and running it in the browser may be easier than debugging with the Insert PHP plugin. The error messages are likely to be more pertinent. After it runs independently, it should run OK with the Insert PHP plugin.
Will
Hi Surya,
The reason Insert PHP isn’t working is because it can’t. The code within the [insert_php]…[/insert_php] tags can’t reach outside itself. Everything it needs to run needs to be between those tags.
Unfortunately, I can’t help with the themes. Sorry about that.
Will
Hi DewaSurya,
Although Insert PHP is a plugin, it won’t run proprietary WordPress functions.
Insert PHP will work only for PHP code that would work outside of WordPress on a stand-alone page.
As an example, this would not run on a stand-alone page by itself
<?php comments_template(); ?>
because comments_template() isn’t found on the page.
Any function that’s called with code between [insert_php]…[/insert_php] tags must be defined within the tags. For example, this would work on a stand-alone page:
<?php echo myfunction(); function myfunction() { return 'Hello World!'; } ?>
Because that works on a stand-alone page, this also would work:
[insert_php] echo myfunction(); function myfunction() { return 'Hello World!'; } [/insert_php]
Will
immanence, what you have is JavaScript and HTML. Insert PHP will accept only PHP code.
The local syndication plugin might be used to pull both the JavaScript and HTML into the post or page.
https://www.ads-software.com/plugins/local-syndication/If you prefer not to use that plugin and you can’t find another plugin that works for what you want to do, then I think the JavaScript part of your code will need to be pulled in from an external file. Just the JavaScript, not the noscript tag or the other HTML code. This article has information:
https://www.willmaster.com/blog/javascript/external-javascript.phpSorry Insert PHP won’t do the job for your code.
Will
Kimber, if this doesn’t work:
[insert_php] echo 'Server date and time is: '; echo date('l, F j, Y \a\t G:i:s'); [/insert_php]
Then:
1. Ensure the Insert PHP plugin is installed.
2. Ensure the plugin is activated.
3. When adding the code to posts or pages, use the “Text” tab instead of the “Visual” tab.
Test things until the above code works on your page. Then, modify it with your custom content.
To test custom content, save the PHP code to a separate web page. Replace [insert_php] with <?php and replace [/insert_php] with ?>
Put the test web page on your server and type its URL into your browser.
~ If it works, then it should also work with the plugin (<?php and ?> replacements reversed first, of course).
~ If it doesn’t work on the separate test page, fix what needs fixing until it does work. Then use the code with the plugin.
Will
estr, each [insert_php]…[/insert_php] block of code needs to be complete. Complete being that it will run independently.
[insert_php]if(is_single()){[/insert_php]
won’t run by itself.
Insert PHP works by putting the code found between the [insert_php] [/insert_php] tags into an eval() function. The code in the eval() function won’t reference PHP code outside the function.
This will work:
[insert_php] function is_single() { return true; } if (is_single()) { echo '<p>Some text.</p>'; } [/insert_php]
But it won’t work if it’s broken up into separate [insert_php]…[/insert_php] chunks.
Will
You’re welcome, nvijaya. And thank you for your kind words.
Will
Forum: Plugins
In reply to: [Local Syndication] Interesting thought for useSorry, bernardberry646, I completely missed your question.
Yes, any web page available to browsers can be pulled in so long as the server the page is requested from allows it to happen.
Local Syndication, however, doesn’t run JavaScript. When page content depends on JavaScript, what’s inserted into the WordPress page may be different than expected, perhaps even surprising.
Will
nvijaya, the PHP code runs with errors.
The PHP code used with Insert PHP needs to be able to run independently before it will run without errors within Insert PHP.
If you put this into a file named test.php
<?php $name = get_post_custom_values('staff_name'); $image = get_post_custom_values('staff_image'); $info = get_post_custom_values('staff_info'); $email = get_post_custom_values('staff_email'); $contact = get_post_custom_values('staff_contact'); foreach ( $image as $key => $value ) { echo $value; foreach ( $name as $key1 => $value ) { if($key == $key1){ echo "<span class='staff_name'>".$value." "."| </span>"; } foreach ( $info as $key2 => $value ) { if($key == $key1 && $key1 == $key2){ echo "<span class='staff_info'>"." ".$value."</span><br />"; } foreach ( $email as $key3 => $value ) { if($key == $key1 && $key1 == $key2 && $key2 == $key3){ echo "<span class='staff_detail'><span style='font-weight:lighter;'>Email:</span>"." ".$value."<br />"; } foreach ( $contact as $key4 => $value ) { if($key == $key1 && $key1 == $key2 && $key2 == $key3 && $key3 == $key4){ echo "<span style='font-weight:lighter;'>Direct:</span>"." ".$value."</span><br /><br /><br /><br /><br /><br />"; } } } } } } ?>
Then load test.php to your server and type its URL into your browser. You’ll see what I mean.
The error I noticed immediately is the code between the [insert_php][/insert_php] tags calls a function get_post_custom_values(). Yet, there is no such function available in the code between the [insert_php][/insert_php] tags.
I think get_post_custom_values() is a WordPress function. Unfortunately, WordPress functions aren’t available to PHP code between the [insert_php][/insert_php] tags.
Intuitively, a person could think WordPress functions would be available for use here as they are available for use in WordPress plugins. But that’s not the case. The code between [insert_php][/insert_php] tags is never made a part of the plugin. Instead, Insert PHP runs the code within an eval() statement.
Once your PHP code runs independently on a page by itself, then it can be used with Insert PHP.
Will
Thanks, Roger Sanchez. Appreciate the kind words ??
Will
The plugin must be activated and the PHP code must be between the [insert_php] and [/insert_php] codes (no <?php or ?>).
Also, type or paste the code into the text box under the “Text” tab, not the “Visual” tag.
Thank you for the update, Stacy.
Will
What you describe does indicate there is a conflict somewhere.
Verify you used the correct code. There should be an underscore character within the tag, [insert_php] instead of [insertphp]. I mention it because in your question the tags don’t have the underscore character.
If the issue persists with:
[insert_php] echo "test"; [/insert_php]
Then let me suggest not using Insert PHP on WooCommerce pages (I’m assuming WooCommerce is more important than Insert PHP).
My hunch is WooCommerce grabs the entire page content and, because it doesn’t recognize [insert_php] as a valid shortcode, it just leaves it as is. But that’s just a hunch.
Will
Sorry, Insert PHP won’t bypass those WordPress’ actions. Any content published with Inert PHP is done before those WordPress functions.
One way to bypass those WordPress functions is with the iframe feature of the Local Syndication plugin. The Other Notes page
https://www.ads-software.com/plugins/local-syndication/other_notes/
has links to instructions.Will