Place custom field above description
November 15, 2024 · AI Conversations
### 1. **Create or Modify a Child Theme (if not already using one)**
It's always recommended to use a child theme to ensure that customizations persist after theme updates.
### 2. **Override GeoDirectory Template Files**
GeoDirectory uses template files to display the content on the front end. You'll need to override the relevant template in your child theme.
The template you need to modify is typically located in:
wp-content/plugins/geodirectory/templates/contents/place.php
You can copy this file into your child theme so it can be customized without losing changes during updates.
Copy it to your child theme’s folder:
wp-content/themes/your-child-theme/geodirectory/contents/place.php
### 3. **Edit the Template**
In the `place.php` file, find the section where the place description is displayed. It will look something like this:
<div class="gd-place-description">
<?php the_content(); ?>
</div>
To add the custom field above this, you can insert the code to display your custom field just before this section. For example, if your custom field is named "custom_field", you can retrieve it using:
$custom_field_value = get_post_meta( get_the_ID(), 'custom_field', true );
if ( !empty( $custom_field_value ) ) {
echo '<div class="gd-custom-field">' . esc_html( $custom_field_value ) . '</div>';
}
This will output the custom field's value above the description if it's not empty.
### 4. **Style the Custom Field (Optional)**
If necessary, add custom CSS in your child theme's `style.css` to style the new custom field.
For example:
.gd-custom-field {
margin-bottom: 20px;
font-size: 16px;
font-weight: bold;
}
### 5. **Test the Changes**
After making the changes, visit a place page to see if the custom field appears above the description.
Let me know if you need further details!