Thank you.
So, I built my own shortcode and I’m sharing it here in case anybody is interested in it. I’m sure it’s not the cleanest code ever written as I’m not very experienced in PHP.
This shortcut takes the values of two of my ACF fields (project title, a plain text field, and project type, a checkbox field which can contain multiple values) of a specific post defined with the post ID in the shortcode. In addition, it requests the post’s permalink and its featured image URL using built-in WordPress functions. Then it uses these 4 values to create the HTML code I wanted to include in a Content Area element in the PRO page builder.
function fd_portfolio_item_shortcode( $atts ) {
// Shortcode attribute to enter the post ID
$atts = shortcode_atts( array(
'id' => '',
), $atts );
// Variables
$permalink = get_permalink( $atts['id'] ); // the post's permalink
$featured_image_url = get_the_post_thumbnail_url( $atts['id'], 'large' ); // the post's featured image url
$acf_project_title = get_field( 'homepage_title', $atts['id'] ); // the post's ACF project title field value
$acf_project_types = get_field( 'project_type', $atts['id'] ); // the post's ACF project type field value
// Generating the content
if( $featured_image_url ): ?> <!-- HTML output if there's a featured image -->
<a class="pwi-container" href="<?php echo $permalink; ?>">
<div class="pwi-image" style="background-image: url('<?php echo $featured_image_url; ?>');"></div>
<div class="pwi-text-container">
<p class="pwi-secondary-text"><?php echo implode ( ", ", $acf_project_types ); ?></p>
<p class="pwi-primary-text"><?php echo $acf_project_title; ?></p>
</div>
</a>
<?php else: ?> <!-- HTML output if there's no featured image -->
<a class="pni-container" href="<?php echo $permalink; ?>">
<p class="pni-secondary-text"><?php echo implode ( ", ", $acf_project_types ); ?></p>
<p class="pni-primary-text"><?php echo $acf_project_title; ?></p>
</a>
<?php endif;
}
// Register the Shortcode
add_shortcode( 'fd-portfolio-item', 'fd_portfolio_item_shortcode' );
Now I can just use the shortcode [fd-portfolio-item id="123"]
(replace 123 with the portfolio post ID) in a Content Area element to show my content. It works very well, but feel free to make suggestions on how to improve my code.