I have been using the Twenty Twenty-Two theme in Wordpress that is running on AWS lightsail multisite WP environment. I have found it easy enough to layout content using block editor.
Now I want to query data from the database (for now just want to use the Wordpress database where I added a table) and display that information.
I see tutorials for older versions of WP but I can not find any resource that provide much guidance on this. What I know thus far is I can not simply add php code to a page or post.
Please help. Frustrated at this point. Seems like this would be common task.
The question of "[how to] simply add php code to a page or post [in WordPress]" is not easy to answer because there are multiple ways you might approach it.
I recommend you search for phrases like
"add php WordPress functions.php"
"Why Child Theme custom php WordPress"
"how-to simple WordPress plugin custom php"
Good luck!
First of all, thank you for bothering to read this topic, I feel like this is going to be a long and painful one, as I'm trying for about 7-8 hours now to get what the hell is happening with this plugin.
I am a developer, so I know what I'm doing, and this isn't my first page I did using WordPress.
The problem started when I started reading up on woocommerce's documentations which are widely known as quite poorly documented.
Since I made a custom theme, which I have had before already, I've decided to use the overwrite method as well as the woocommerce.php method for customizing the plugin to fit the site as I'd like it to.
The woocommerce_content(); is customized now, and nicely working as well as the product pages (single product page) which are customized as well, and working.
As soon as I try to access the account features, nothing happens. I've tried adding echoes for debugging purposes to the my-account.php, but it does not echo what I write, so I assume the shortcode cannot load for some reason, because it does not reach the my-account.php page as it should, and it points somewhere else perhaps?
Then I've noticed that when I click the "Add to cart" button, it appends the element with a "View cart" button as well, so me thinking this is working, I left it as it is. For like 5 seconds, because right after a page refresh, or navigating to another page, the content of the cart gets empties, I cannot even see the cart page, nor the login page, nor the create account page, or anything in fact.
Everything is working that is inside my "wp-content\themes\mytheme\woocommerce" folder, but nothing else that is inside my
"wp-content\themes\mytheme\woocommerce\any-subfolder"
The woocommerce system status does not show any error, nor the PHP error log, nor anything else.
I have a VERY long list of "Overrides (WooCommerce):" which I don't want to paste here because of reasons.
The only success when I was able to at least get something out from the plugin, is when I used the wordpress function "do_shortcode();" and added the myaccount or cart shortcode myself to a page, THAT worked, and printed it out, however I'd like to use the original method, so the code won't get too complex for later on.
Every other site is working fine, I'm currently running this on localhost, cookies working, sessions working, I log everything yet there is no error, mod_rewrite working correctly, yet I am stuck.
Looking for a patient gentleman to help me on this painful day...
EDIT:
Added "[woocommerce_my_account]" to the "shop" page which page's file is the "woocommerce.php" has actually loaded up the correct my-account.php from "themeroot/woocommerce/myaccount/my-account.php" It echoes out my debug messages as well, so the shortcodes should be working, perhaps this isn't just a woocommerce related issue?
EDIT2:
After fiddling around a LOT, I've come to understand that the wrapper hook it is supposed to do (div id=content and div id=main) does NOT get hooked in it, perhaps it is just a small problem, since I've removed them with remove_action, and the "Shop" page still displayed properly... I have NO idea what is going on with this plugin, but I don't have the luxury of time to fiddle around with it... This is such a pain...
EDIT3:
The plugin works perfectly on any other basic theme, so there is something up with my custom theme. Even after hours of searching the differences between the default theme (twenty-fifteen) and mine, I have not found the solution.
I have solved the problem... It is of course entirely my fault, the problem is just that woocommerce has so poor documentation, I did not really thought about this.
For anyone out there creating custom themes for WordPress, please note that in order for your page.php to actually use the shortcode of the page you have navigated on, you must print out the content of the page (the_content();).
This was my solution for my mistake that took many many hours...
I have WordPress 4.1.1 installed. I want to be able to write PHP code for specific pages. I found an answer on here which seemed like the best option I have come across so far, this answer can be found here:
How to add a PHP page to WordPress?
But - this does not seem to work and I cannot figure out why.
I followed the steps accordingly and I was able to complete all steps with no problem but when I preview the page its blank.
My only guess is that this might have something to do with version 4.1.1 - is there any reason this method would not work with version 4.1.1?
Your help is greatly appreciated.
If you need to add PHP to a page you need to open your themes template files in a text editor of your choice.
If enabled, access the Theme Editor from the Administration > Appearance > Editor menu.
http://codex.wordpress.org/Appearance_Editor_SubPanel
If your pages are blank you might have an error with your PHP code.
Personally I use this plugin:
https://wordpress.org/plugins/php-code-for-posts/
However you can also use custom page templates: http://codex.wordpress.org/Page_Templates#Creating_a_Page_Template
It depends what your personal code needs are.
I installed a new plugin (optimizely) on my Wordpress site. I need the new plugin and it isn't optional. However, since installing it, the shortcode on another plugin (download monitor) no longer works.
All the downloads that I had in my posts just disappeared.
the php shortcodes in my posts look like this: [download id="2981"]
I tried deactivating the optimizely plugin, but it doesn't make a difference. I think something got changed in the settings of wordpress??? This is my guess. The odd thing is that optimizely uses php short codes as well, so it can't be that short codes are no longer active...
Can anyone tell me where I should look?
UPDATE:
I also have Jetpack installed... which has a features called shortcodes. I just tried to insert a YouTube video in to a post using their shortcode format and it didn't work either!
UPDATE2:
Cancel previous update... other short does work fine. My bad.
Hello everyone i'm new to wordpress and trying to learn more about it , well the thing is that i installed a new theme to my blog and it seems everything works fine except the shortcodes functionality, and i don't know why or where should i look for that problem this is a picture to my admin posting page it shows that i choosed the button short code and nothing happen no parameters to fill in and even when i press the send to editor button nothing happen , please help me to find out my problem :
the picture :
There are posts online that complain about the Shortcode Generator not working. You should first turn on debug in your wordpress config wp-config.php and see if there are errors being logged.
The best solution is to learn how to add shortcodes manually, it's easy [myshortcode]...[/myshortcode]