0

I would love some help or a direction to a point of solid research on this issue.

From what I understand, and my current research, wordpress by default out of the box does not support php files to be included as shortcodes in wordpress posts and pages. They have their reasons, but I need it to work. So I did so, with the following function.

//to allow me to include php file content as a short code in posts and pages
function includeme_call($attrs, $content = null)
    {

        if (isset($attrs['file'])) {
            $file = strip_tags($attrs['file']);
            if ($file[0] != '/')
                $file = ABSPATH . $file;

            ob_start();
            include($file);
            $buffer  = ob_get_clean();
            $options = get_option('includeme', array());
            if (isset($options['shortcode'])) {
                $buffer = do_shortcode($buffer);
            }
        } else {
            $tmp = '';
            foreach ($attrs as $key => $value) {
                if ($key == 'src') {
                    $value = strip_tags($value);
                }
                $value = str_replace('&', '&', $value);
                if ($key == 'src') {
                    $value = strip_tags($value);
                }
                $tmp .= ' ' . $key . '="' . $value . '"';
            }
            $buffer = '<iframe' . $tmp . '></iframe>';
        }
        return $buffer;
    }

    // Here because the funciton MUST be define before the "add_shortcode" since 
    // "add_shortcode" check the function name with "is_callable".
    add_shortcode('includeme', 'includeme_call');

Major Problem moving forward though, that I have not figured out, I tried every include plugin, every include post to page plugin, literally every test I could possibly think of to get a standard wordpress image tag such as...

    <figure class="wp-caption article-pic" itemprop="image" itemscope="" 
    itemtype="https://schema.org/ImageObject">
      <img itemprop="url" src="wp-content/uploads/file.jpg" width="502px;" 
       height="280px" alt="Leigh Woods">
    <figcaption class="wp-caption-text">
       Leigh Woods
    </figcaption>
   </figure>

that was hard-coded in a php file within the theme directory then included with the above function in a wordpress page using this shortcode.

[includeme file="wp-content/themes/theme-directory/front-page/home.php"]

to register with the Wordpress SEO (Yoast) functions that is supposed to create the facebook, twitter and regular open graph aka og:image located in the head like this

<head>
<meta property="og:image" content="wp-content/uploads/file.jpg" />
</head>

--> also keep in mind, I've tested this with other Plugins that Generate Open Graph Metas, and if it wasn't a plugin I've tested it was a hard-coded function to generate open graph metas for images, while deactivating yoast, still doesn't wanna work. Then I tested by placing the html of the image src directly into the wordpress page without a shortcode then works perfectly, but completely defeats the purposes of needing the Includeme Function, which I truly need and also truly need to be able to hard-code images into php files.

My current thoughts and research point me to some facts, and I am uncertain if these are correct thoughts here... The Wordpress SEO Settings for the Open Graphs metas might be executed in the WPSEO Plugin Constructor, before the functions.php file is executed??? I wrote a letter to Yoast as well, about some concerns for developers needing to use filters in the functions.php file to default settings for yoast, impossible to do now and deprecated in 2015 because, I think settings for yoast or registered early in the constructor i think. Another thought could be that this is some bad code for the includeme function to buffer correctly to be able to register??

Another thought is that the visual editor can only trigger the dynamic injection of an image to the og:image meta if the img is placed physically in the visual editor page

Like I said I tried this in other ways to include php files through other code, or other widely used plugins, and then test reverse situations, by using other open graph plugins or functions.

We can think about another plugin "Soliloquy" for image sliders and such, uses short codes into the visual editor of a post or page, and I think this allows it to register in Yoast og:image, it been a while since I've tested it, but Im pretty sure it works. How did they do that? But keep in mind the I need it as php file from the filemanager included as a shortcode???

If there is no solution to this, and it turns out to be a wordpress limitation by default, then as far as id be concerned it'd be a wordpress bug, a big bad one. Wordpress should allow all options to include php content in the visual editor and post pages.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.