• Resolved quitmakingsense

    (@quitmakingsense)


    On the page which contains the pdb_single shortcode, I’d like to have code to create a meta tag for og:image in the header, setting the tag content to the image url stored in an image field I have in the table. I’ve had no problem manipulating this field with a custom template for the ‘single’ shortcode and some php, but what will work in the page body breaks the whole page when placed in header.php (viewing page source shows that rendering stops where the custom code in inserted).

    Any suggestions on how to accomplish this?

    Thanks!

    https://www.ads-software.com/plugins/participants-database/

Viewing 9 replies - 1 through 9 (of 9 total)
  • Plugin Author xnau webdesign

    (@xnau)

    You may not be able to access plugin functions or values in the WP header template, but that may not be the problem. You just need to debug it more carefully. I’ve never tried to do this, so I can’t offer any suggestions…sorry.

    Thread Starter quitmakingsense

    (@quitmakingsense)

    I did check the php error log as well as the apache error log and there were no errors relating to the code, so it’s a head scratcher. Thanks anyway.

    Plugin Author xnau webdesign

    (@xnau)

    Typically, if it’s a syntax error, there won’t be an error in the logs. You just have to study your code for mistakes.

    Thread Starter quitmakingsense

    (@quitmakingsense)

    Ok, so I’ve learned one thing by doing some testing – created this basic loop:

    <?php while ( $this->have_groups() ) : $this->the_group(); ?>
    <?php while ( $this->have_fields() ) : $this->the_field(); ?>
    <?php echo ‘<!– foo –>’; ?>
    <?php endwhile; // end of the fields loop ?>
    <?php endwhile; // end of the groups loop ?>

    If I put this in my custom single template after the production code, it produces no output. If I move it to just before the production code, it outputs a bunch of <!– foo –> as expected, but the production code does not produce any output. Conclusion: I cannot loop through a single record more than once a single page without doing something special. Suggestions?

    Thanks!

    Plugin Author xnau webdesign

    (@xnau)

    OK, the “custom single template” is only for the plugin output. The WordPress page will use it’s own template. You cannot put the WordPress content loop in the custom single template. Is that what you were trying to do?

    Thread Starter quitmakingsense

    (@quitmakingsense)

    That is what I was using it for, plugin output. Specifically, I want to create a meta tag in the page header that utilizes data from a single record when the URL contains a valid var (pdb=xxx).

    The code snippet I posted above was inserted in my pdb_single template, in addition to the code that was already there and as indicated it would or would not output depending upon whether it was placed before or after the ‘main’ code, and likewise the main code was affected by it’s position. I’m just feeling my way through this and trying to get some feedback here.

    Let’s refocus the discussion. Can you tell me how I would go about doing what I need to do, assuming it would be done? Perhaps I need to create a separate template just for my header code, then call in in the header.php for my site with do_shortcode() – does that sound like a viable approach? Just searching for some guidance.

    Thanks a bunch for all your help thusfar.

    Thread Starter quitmakingsense

    (@quitmakingsense)

    I.e. – create pdb-single-meta.php with my code, then in the header:

    do_shortcode(‘[pdb_single template=”meta”]’)

    ?

    Plugin Author xnau webdesign

    (@xnau)

    I don’t know if that will work…if I were doing this, I would use the record ID in the URL to get the record and then use the data in the record to set up the meta tags in the header.

    You can put something like this in your header.php:

    <?php
    $pdb_record = Participants_Db::get_participant(filter_input(INPUT_GET, 'pdb')); ?>
    <meta property="og:image" content="https://domain.com/wp-content/uploads/participants-database/<?php echo $pdb_record['image'] ?>" />
    Thread Starter quitmakingsense

    (@quitmakingsense)

    Thanks – don’t think I would have figured that out without your help or a code ref / codex for your plugin. Added a bit to allow qualification of the page and posting here in case someone else is trying to do this:

    <?php
        if (is_page( 'tcrp' ) ) {
            $pdb_record = Participants_Db::get_participant(filter_input(INPUT_GET, 'pdb'));
            $output = '<meta property="og:image" content="https://domain.com/wp-content/uploads/participants-database/' . $pdb_record['photo'] .'" />';
            echo $output;
        }
    ?>

    Of course, other fields can be pulled to build tags for og:title, og:description, etc.

    Thanks again for all your help.

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘How to create og:image meta tag on pdb_single page’ is closed to new replies.