Jump to content

Using Custom Fields to populate an href


brookruck

Recommended Posts

I am working on a site Wordpress site where I have used a plugin to create some custom fields that appear when a user is creating a new page. The code below is a snipet from the template that calls those custom fields and places the user input into the proper sections of the page. 

 

The first line is working perfectly, the second piece of code is where my error is coming from. The code in bold is the call to the user input url. I need this to be input into the button shortcode. I am not very experienced with php, so I am hoping that I have just made a simple syntax error. 

 

Any help would be greatly appreciated!

....

<p><?php echo types_render_field("copy-section");?></p>
		  		
<?php echo do_shortcode('[button color="accent-color" hover_text_color_override="#fff" size="large" url="' . echo types_render_field("signup-link"); . '" text="SIGN UP TODAY - It's Free and Secure!" color_override="#d28743"]'); ?>

....
Link to comment
Share on other sites

There may be more issues, but the things that jump out at me are the extra "echo" and semi-colon. Try changing this:

<?php echo do_shortcode('[button color="accent-color" hover_text_color_override="#fff" size="large" url="' . echo types_render_field("signup-link"); . '" text="SIGN UP TODAY - It's Free and Secure!" color_override="#d28743"]'); ?>

To this:

<?php echo do_shortcode('[button color="accent-color" hover_text_color_override="#fff" size="large" url="' . types_render_field("signup-link") . '" text="SIGN UP TODAY - It's Free and Secure!" color_override="#d28743"]'); ?>

If that doesn't work and you're still getting errors, please let us know what the exact message is (or messages are).  :happy-04:

Link to comment
Share on other sites

Sorry, I'm not very familiar with do_shortcode() or types_render_field().

 

Have you tried echoing the result from types_render_field() to see if it's what you expect?

<?php
echo do_shortcode('[button color="accent-color" hover_text_color_override="#fff" size="large" url="' . types_render_field("signup-link") . '" text="SIGN UP TODAY - It's Free and Secure!" color_override="#d28743"]');
 
echo '<p>types_render_field() Output: ' . types_render_field("signup-link") . '</p>';
?>
Link to comment
Share on other sites

Thanks again for taking the time to reply.

 

I tried your suggestion, and it did echo the correct data. I still wasn't able to get it to put it into the proper url field for the button shortcode though. But we ended up having to scratch that custom field and do a work around in order to complete the project on time. It does still bother me that I wasn't able to work this issue out though! 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.