-->

I am still working throughout the current coronavirus outbreak, although at a reduced capacity. Please do get in contact if you have any questions.

Select Page

Are your WordPress custom fields showing as code on your website as Raw HTML instead of rendered HTML? This may be because you have updated WordPress and are using a deprecated function like the_meta(); This function no longer works in the same way in newer versions of WordPress.

Are you using a custom or off-the-shelf WordPress theme?

It is likely you are experiencing this because your theme was custom-built or you bought it as an off-the-shelf theme and haven’t updated it in a long time. If it is the latter, see if you can find the latest version of the theme, pay for a new license and install it on your website.

Updating the deprecated Custom Fields code

If you don’t have an upgrade path for your theme, then you will need to update the deprecated functions for newer ones. In this case, I had the following code which is now deprecated.

<?php the_meta(); ?>

The new function to replace this is get_post_meta(); so to use this function you will need to find the name of the custom fields, this can be found in the admin area. Sometimes these fields are hidden but you can show them using the ‘screen options’ at the top of the screen and checking ‘custom fields’.

The next step is to identify where this code is being loaded, it is PHP code, so will likely be in the header, footer or a page template. To narrow this down we can look on the front end of the website and find where it shows incorrectly. Then track it back to a part of the website. To update templates you will need access to the files on the server through SSH, SFTP, Version Control or something like File Manager in CPanel.

Next, we replace the code with this code

<?php $myCustomField = get_post_meta($post->ID, ‘name-of-custom-field’, true); ?>

<?php echo $myCustomField;  ?>

What we are going is getting the custom field with the name of ‘name-of-custom-field’, so you need to swap this for your customs field’s name. We are saving it to a variable called myCustomField, which you can change to something more suitable. Then we are echoing out that variable onto the page. If you change the name of the variable, be sure to change it where it is echoed onto the page.

Need help fixing your WordPress website? Get in contact using the form below

2 + 12 =