Add content form metabox to ribbon content PHP

I want to show specific text from metabox in ribbon that is placed on photo.
And to show it only if I have text in metabox.

I have CSS ribbon:

.ribbon figure {position:relative;}
.ribbon figure:before {

    position:absolute;
    top:15px;
    right:0;
    background:#5fc8c2;
    padding:5px 10px;
    color:#fff;
    font-weight:700;
    z-index:2;
}

I have metabox for custom post types registered in the system.

$discount_text = $accommodation_obj->get_custom_field('discount_text', true);

And I can show it if there is text.

if (!empty($discount_text)) {
echo $discount_text ;
}

However it will not show the text inside a ribbon content.

I tried to add this:

if (!empty($discount_text)) {
echo $discount_text . '<div class="ribbon" >';
}

If I add content in css like:

content:"SALE";

it will show the text SALE properly, but that is static text and not what I want.
Any hint?

Read more here: Add content form metabox to ribbon content PHP

Leave a Reply

Your email address will not be published. Required fields are marked *