• Resolved rose18

    (@rose18)


    This is a nice plugin! Is there a way to add dynamic values to the newly added attribute?
    Say I want the value to be the post title, instead of typing in the post title manually, is there a way to dynamically insert the post title?

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author websevendev

    (@websevendev)

    Sure, you could add an attribute data-post-title and give it the placeholder value %ROSE18_POST_TITLE% and then add this filter to your codebase:

    add_filter('render_block', function($content) {
    	return str_replace('%ROSE18_POST_TITLE%', esc_attr(get_the_title()), $content);
    });

    to replace the placeholder value with the dynamic value.

    Thread Starter rose18

    (@rose18)

    Thank you @websevendev ! Your way works!
    I did try to create a custom shortcode to display the post title and added the shortcode to the value field to see if that will work. Unfortunately, it didn’t. It will also be great if we can do that.

    Plugin Author websevendev

    (@websevendev)

    This would work for shortcodes, probably:

    add_filter('render_block', 'do_shortcode', 50);
    Thread Starter rose18

    (@rose18)

    @websevendev

    Using shortcode in the the value field actually works.

    I just noticed that I had a typo in my attribute, I have it has ‘arial-xxx’, instead of ‘aria-xxx’. That’s why it was showing the shortcode as plain text

    thank you for helping!

Viewing 4 replies - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.