The grid of photos is part of post content, so you’d want the violet box inserted between text and photo content. To do that you need a shortcode (or custom block). Shortcodes are something I understand well. Custom blocks not so much.
The wpb_author_info_box() function can be made into a shortcode handler with something like:
add_shortcode('auth_info', 'wpb_author_info_box');
The function will need some modification as well (details below). As a shortcode, you will remove the related add_action() call. (FWIW, “the_content” is really a filter, not an action. The two are closely related so add_action() can work, but it’s semantically incorrect.)
To use the shortcode, add “[auth_info]” to the post’s content where you want the violet box to appear.
Documentation on creating shortcodes is available. You only need to be concerned with the most basic form of shortcode. There doesn’t need to be any attributes, nor is there a need for the self-closing form.
I think maybe the only change you really need in your function is to remove $content from the return value. For the line before return, do something like:
$content = '<footer class="author_bio_section" >'. $periodo_affitti . $author_details . $saldo .'</footer>';
If your $saldo value is not what you expect, the issue lies in the code used to save the selected value. It’s saving “option2” instead of “All’arrivo”. If you’d rather not deal with altering the saving code, you could make use of the existing scheme and place the logic in the output code. Something like:
switch ( get_the_author_meta( 'saldo', $post->post_author )){
case 'option1':
$saldo = '15 gg. prima dell'arrivo';
break;
// more option values could be added here
default:
$saldo = 'All'arrivo';
};
However, this is only workable if all posts have all the same possible selections. If the options vary by post, then you would need to deal with altering the saving code.
You can break out $saldo and $periodo_affitti into different sections. Do you want different sections within the same <footer>
element or outside of it? Either way, you wrap the meta value in appropriate HTML tags, like so:
// Get saldo
$saldo = '<div class="saldo">'. get_the_author_meta( 'saldo', $post->post_author ) .'</div>';
You can then style the saldo div as desired using .saldo
as the CSS selector.
Whether $saldo is inside or outside of <footer>
depends on where you insert $saldo
in the final assignment to $content before return. The above example assumes you’ve corrected the saving code to save the correct value instead of “option1” and the previously suggested switch/case logic is not used.
-
This reply was modified 1 year, 3 months ago by bcworkz. Reason: code format fixed