• Resolved nateonawalk

    (@natesirrah)


    Hey Micah,

    On my new ‘lil Pokemon site, I’m trying to add a call to Widgets on Pages Shortcode within the figure generated by mPress. I’d like to be able to put responsive objects on both the left and right of the central random image found within the iFrame (you can see an example of this when you click the “eevolve” button on the homepage). Because the figure is displayed as a block, I’d like to float these widget sidebars within the same div (and as a result, the same figure).

    I’ve made two widgets with WOP and put some filler text. I titled them “Sidebar1_Left” and “Sidebar2_Right.” The correct shortcodes for these two widgets are:

    [widgets_on_pages id=”Sidebar1_Left”]
    &
    [widgets_on_pages id=”Sidebar2_Right”],

    respectively.

    I tried to simply insert these into the plugin between the <figure> tags using the php echo do_shortcode function:

    if ( $display_caption ) {
    					$image_html = "<figure>
    						<?php echo do_shortcode('[widgets_on_pages id="Sidebar1_Left"]'); ?>
    					{$image_html}<figcaption>{$image->post_excerpt}</figcaption>
    						<?php echo do_shortcode('[widgets_on_pages id="Sidebar2_Right"]'); ?>
    					</figure>";
    				}

    …but that broke the site with a T-String error.

    And so I’m stumped! Could you advise either the 1) correct place for me to put this code or 2) an alternate approach to solving the puzzle?

    Thanks so much!
    -NS

    https://www.ads-software.com/plugins/mpress-image-refresh/

Viewing 7 replies - 1 through 7 (of 7 total)
  • There is a filter that will allow you to edit the output without editing the actual plugin. Editing the plugin files is discouraged as you would lose your changes when the plugin is updated in the future.

    You can create a file in your wp-content/plugins/ directory and place this code in it to edit the output to fit your needs:

    <?php
    
    /*
     * Plugin Name: mPress Image Refresh - Custom Output
     */
    
    add_filter( 'mpress_image_refresh-image_html', function ( $image_html, $image, $atts ) {
    	$image_html = '<figure>';
    	$image_html .= do_shortcode( '[widgets_on_pages id="Sidebar1_Left"]' );
    	$image_html .= "<figcaption>{$image->post_excerpt}</figcaption>";
    	$image_html .= do_shortcode( '[widgets_on_pages id="Sidebar2_Right"]' );
    	$image_html .= '</figure>';
    
    	return $image_html;
    }, 10, 3 );

    I didn’t test it, but it should be correct. If it doesn’t work for you, just let me know.

    Thread Starter nateonawalk

    (@natesirrah)

    Dear Micah, thanks for this! I haven’t yet been able to get the code working…I inserted it character-for-character into a PHP file, which I called “mpress-filter.php,” and put that file in the wp-content/plugins directory of my site.

    To get it to work,

      Do I need to name it something different?
      Do I need to actually place the file in the mpress-image-refresh folder?
      Is it that the widgets are just getting sized out by the other figure element in the iFrames? I’m not able to see the widgets_on_pages by digging around in the DOM code.

    Thanks again for your help!
    Best,

    -NS

    Sorry, I didn’t mention activating the plugin, but that is a required step after placing the file in the wp-content/plugins/ directory. The file name you used is just fine. If you place the file in the mpress-image-refresh folder, it won’t work.

    This function will actually process the [widgets_on_pages] shortcode immediately, so you won’t see the shortcode output in the DOM unless the widget is disabled. You would always just change the return $image_html; line to something like return 'Hello World!'; just to see if it is working properly.

    If you still can’t get it to work, then feel free to shoot me an email and we can figure out a way that I can take a closer look.

    Thread Starter nateonawalk

    (@natesirrah)

    Hey Micah,

    So I went ahead and activated the plugin, I had indeed missed that step — when I tested my page, blog posts showed a blank page with this error:

      Warning: Cannot modify header information – headers already sent by (output started at /wp-content/plugins/mpress-filter.php:18) in wp-includes/pluggable.php on line 1196

    which seems to imply an issue in the Loop?

    Thanks again for all the help!
    -NS

    @natesirrah,

    It is likely that there may be an extra space before the opening <?php tag from when you copied the code into the file. Removing any spaces should solve the issue.

    Thread Starter nateonawalk

    (@natesirrah)

    Dear Micah,

    I believe the problem ended up being either two extra lines at the end of the file, or a space before a */…whichever it was, the plugin no longer breaks posts, which is great!

    Instead, there is another issue — either a) the image that the original plugin was pulling no longer appears [and the two text widgets I’m pulling with the new filter do] or b) an image appears, but it is no longer random.

    For the sake of clarity, here is the site. When a visitor clicks the main button, a lightbox activates that renders 1/8 posts randomly. 6/8 of those posts now only render the widgets_on_pages text widgets and the figcaption; 2/8 of the pages render an image from my bank of random images, but they are no longer random (Jolteon and Espeon). Every time a user gets a Jolteon or Espeon page, it is the same artwork.

    At its normal functionality (with the new filter plugin disabled), on click the site renders a lightbox with 1/8 of the posts, and that post has mPress shortcode that pulls from a span of relevant random images.

    Thanks again Micah! Do you have a donate button on your site?
    Best,

    -Nate

    It is sounding like there may be some issues specific to the context you are working with, but I’m not sure of the details. I’ll shoot you an email and follow up, since it may require getting admin access to the site to see what exactly is going on.

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Including Shortcode Within a Figure’ is closed to new replies.