Support

Account

Home Forums General Issues WordPress function – change variable on post

Solving

WordPress function – change variable on post

  • I use WordPress and ACF PRO plugin.

    I have a function that is added to the section.

    However, I would like this data to change with the posts displayed.

    Function.php:

    function json_ld($type_company = "", $company_name = "") {
        ?>
            <script type='application/ld+json'>
            {
            "@context": "http://www.schema.org",
            "@type": "<?php echo $type_company; ?>",
            "name": "<?php echo $company_name; ?>",
            }
            </script>
        <?php
    }
    add_action( 'wp_head', 'json_ld' );

    Single template

    json_ld(get_field('type_company', $post->ID), get_field('company_name', $post->ID));

    Unfortunately it doesn’t work, is there any other way to do it?

    I want to display the data in the <head></head> section.

  • Did you try using:

    the_field('type_company', $post->ID)

    with both your variables in the same area as the function to see if they are being pulled correctly that route to make sure the issue isn’t with a field name error?

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.