Wordpress Custom Fields not displaying the section - php

I have added a new layout in the Wordpress Custom fields plugin, and after adding it I have added the fields in the corresponding php file too. But for some reason, its printing the code in the browser. I am not sure what I am doing wrong here. I am new to WordPress, so can someone please help me?
Screenshots attached for reference.
PHP file code - https://codeshare.io/GklExO

Figured it out, I had to add an image tag and then it worked fine.
However, there are other PHP files in the site, where
<?php the_sub_field('image'); ?> displays the image, but in this particular case I had to write it as
<img src="<?php echo esc_url($image['url']); ?>"/>
Still trying to understand how this works.

Related

How to properly include php files inside wordpress plugin

Hi I am creating my first custom wordpress plugin.
I have run into an issue when I try to create a link in an included file to one of the plugin menus in the dashboard.
Here is my code for the link
<p>Add a new record</p>
>
As you may have noticed it is using a full URI.
I have tried using ?page=add-members as the href source and it seems to work.
I am wondering if that is the appropirate method to do this or if there is a more standardized way.
Thanks in advance.
I believe what you are looking for is the get_site_url function.
<?php echo get_site_url(); ?>
So ideally you would link it like:
<p>Add a new record</p>
You can read about it on the docs.

including php file in thickbox inline view in wordpress

In one of my wordpress plugins, I am using thickbox function to call another php file in the same plugin directory. The thickbox is displaying content as long as the content is from the same file, if I include another php file in the thickbox, it won't work. Please help.
Here is my code.
<?php
add_thickbox();
include plugin_dir_path(__FILE__) . '/my_php_file.php'; ?>
<div id="cnt-id" style="display:none;">
<h1><?php _e('Select an Item', 'txt-domain'); ?></h1>
<?php print_r($tpl_list);?>
</div>
The thickbox anchor link
<a href="#TB_inline?width=600&height=550&inlineId=cnt-id" class="thickbox">
<?php _e('Open thickbox', 'txt-domain'); ?>
</a>
So when the thickbox page is loaded, it only shows the h1 heading. the array which I am trying to print is just static array created in that included php file.
Any help will be highly appreciated.
Thanks
Just for someone in the similar situation. This is what I found as solution.
I used the absolution URL of the file on my the same location for thickbox with TB_iframe parameter. And I called a separate php file which is including another one with the array data.
That file which I didn't want to be directly accessible, I added the http_referer check via PHP to check if the ref url has wp-admin/post.php in there. That is not a rock solid hack proof but still helps somewhat.
Thanks

Wordpress contact form (404 not found)

I created a template on WordPress and I made an html form. It works well in HTML but doesn't work when used on WordPress. It seems that it doesn't find my contact-send.php page and it displays a 404 Error page.
My permalinks were on default and it didn't work.
Does anyone know how to fix this?
If any of my code is needed, I'll post it. I just didn't because I think it's not a code error once it doesn't find contact-send.php.
Use an absolute URL for the target of your form instead of just action="contact-send.php".
But unless you have particularly unusual requirements for your contact form, you will likely have better results using one of the many popular contact form plugins like Contact Form 7.
Using a well-maintained plugin ensures stability, and more importantly, security. Don't reinvent the wheel if you don't have to.
Your problem can be caused due to 3 reasons.
Giving wrong path in action tag. Using <?php echo get_template_directory_uri(); ?>/contact-send.php will solve this problem.
Missing contact-send.php page in the themes folder. This problem can be solve by adding the page to the themes folder.
Improper .htaccess file. This can be solved by recreating the code for your .htaccess file from Dashboard > Permalinks and paste it in the .htaccess file in the WordPress root directory.
I am giving the explanation in the assumption that your template file is directly in the themes folder.
Add <?php echo get_template_directory_uri(); ?>/contact-send.php. When you write contact-send.php only then it don't find your file which is in your theme. So use this <?php echo get_template_directory_uri(); ?>/contact-send.php in form action. This change may be helpful.

How to add code after "</article>" in content-page.php in Wordpress?

I am using the Shareaholic plugin and they give you a block of code to add the sharing buttons anywhere on your site.
[shareaholic app="share_buttons" id="7726121"]
[shareaholic app="recommendations" id="7962129"]
I want to add this code after </article> tag in the file "content-page.php" in Wordpress. When I do it then nothing happens. When I check the page source then I can't find the code anywhere. It happens even when I add some random word after </article> tag.
How can I make this work?
Thanks!
These are short code and you can't call them directly you need to do it like this.
echo do_shortcode('[shareaholic app="share_buttons" id="7726121"]');
echo do_shortcode('[shareaholic app="recommendations" id="7962129"]');

Social Engine render form issue

I'm adding some pages to default layout editor in SE4. What I do is just adding pages to core_pages table and editing core_content table to add a main container and a middle/right two columns layout. Everything works fine, but now I'm adding default Create Video page (videos_index_create) and I got some problems.
When I add this page via sql, I can obviously see and edit page layout by default layout editor. Actually, when I save changes these don't reflect to live page. If I go to the controller (Video/controllers/IndexController.php) and add
$this->_helper->content->setNoRender()
live page displays right sidebar and middle content, but with
$this->_helper->content->setEnabled()
it shows only the default video upload form.
So I edited create.tpl here
<?php if (($this->current_count >= $this->quota) && !empty($this->quota)):?>
<div class="tip">
<span>
<?php echo $this->translate('You have already uploaded the maximum number of videos allowed.');?>
<?php echo $this->translate('If you would like to upload a new video, please delete an old one first.', $this->url(array('action' => 'manage'), 'video_general'));?>
</span>
</div>
<br/>
<?php else:?>
<?php echo $this->form->render($this); ?>
<?php endif; ?>
Changing the else deleting the echo statement and adding a simple echo 'foo';. Now, live page shows properly my layout (middle+right) with default content ("foo").
I figured thus that the issue is about this line in controller:
$this->view->form = $form = new Video_Form_Video();
but I can't go further… this custom form class (Video/Form/Video.php) seems nothing special, I can't really figure out why its rendering crushes default layout render.
Any social engine expert right here to help me? :)
If its a Zend_Form I am pretty sure you should be doing:
<?php echo $this->form;?>
In your view not call render yourself.
If it is NOT a Zend_Form please post the code for the form it probably has some css or whatnot breaking your layout.

Categories