Support » Plugin: Post Content Shortcodes » post-content-shortcodes-content filter: how to get the posts slug (post_name)?

  • I would like to access the posts slug inside the post-content-shortcodes-content with the following filter:

    add_filter('post-content-shortcodes-content','wrap_post_content');
    function wrap_post_content ($html, $post) {
    	return '<h1> The Posts Slug is: ' . $post->post_name . "</h5></br>" . $html;
    }

    But $post->post_name always returns an empty string. What am I doing wrong?

    Thanks for your help!

    https://wordpress.org/plugins/post-content-shortcodes/

Viewing 1 replies (of 1 total)
  • Plugin Author Curtiss Grymala

    (@cgrymala)

    Your add_filter() call isn’t telling WordPress to send more than 1 parameter to your function. It should look like:

    add_filter( 'post-content-shortcodes-content', 'wrap_post_content', 10, 2 );

    The 10 sets the priority at which the filter should be run (10 is the default), and the 2 tells WordPress that it should send 2 parameters to your callback function.

    Without that 2 in the apply_filters() call, WordPress is only sending the $html parameter.

Viewing 1 replies (of 1 total)
  • The topic ‘post-content-shortcodes-content filter: how to get the posts slug (post_name)?’ is closed to new replies.