• Resolved slawekmuniak

    (@slawekmuniak)


    Hi, I want to customize Post Layout by using this hook:
    https://github.com/YMC-22/YMC-Filter/blob/main/README.md#custom-post-layout

    Why? I want to use some shortcode, but I need to pass there the actual post_id (like: [shortcode id=”{postID}”]). I did not find any simple solution for that in your builder, so I want to override post Layout and make it possible from the code.

    I added code in my theme functions.php:

    add_filter('ymc/post/layout/custom_880', function($output, $post_id, $filter_id, $popup_class, $term_settings) {
    $output = 'TEST';
    return $output;
    }, 10, 5);

    I assume that all items in my filter will show just text: TEST, but I still see my layout from Structural builder. I searched your plugin code, and I do not see any calls for apply_filters(ymc/post/layout/custom…. Is this functionality ready to use or I should do more to make it work?

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author YMC

    (@wssoffice21)

    Hi!

    We’d be happy to help you solve your task. You can override the default post card layout with a custom post card layout. To do this, follow these steps:

    1. In the plugin settings, under Layouts – Post Layout, select Custom Post Layout from the Post Layout drop-down list (see screenshot https://prnt.sc/P4aqCDviVXws).
    2. Then, in your theme’s functions.php file, write the following code and use the filter (hook)
      ‘ymc/post/layout/custom_880’, like in your example:

      add_filter('ymc/post/layout/custom_880', function($output, $post_id, $filter_id, $popup_class, $term_settings) {
      $output = 'TEST';
      return $output;
      }, 10, 5);


      Be sure to check your filter ID (e.g. 880)
      You can improve your code:
      add_filter('ymc/post/layout/custom_880', function($output, $post_id, $filter_id) {
      ob_start(); ?>
      <h2>TEST</h2>
      <p>Post content</p>
      <?php return ob_get_clean();
      }, 10, 3);


      By the way, you can also use Structural Builder, this is a powerful tool for creating a post card!
      This solution is more convenient if you need to output a lot of HTML code. We hope this helps.

    • This reply was modified 2 months, 2 weeks ago by YMC.
    Thread Starter slawekmuniak

    (@slawekmuniak)

    Hi,
    Thanks for your response, I was able to resolve my problem. The main issue on my side was selecting Structural Builder and trying to apply the hook. The PHP hooks does not work with Structural Builder. I had to use Classic Layout for Custom Post Layout type.

    Plugin Author YMC

    (@wssoffice21)

    Good Luck!

Viewing 3 replies - 1 through 3 (of 3 total)

You must be logged in to reply to this topic.