# Custom Excerpt Length not working for me

**URL:** <https://meta.discourse.org/t/custom-excerpt-length-not-working-for-me/284100>\
**Category:** WordPress\
**Created:** [November 1, 2023, 10:57am UTC](https://meta.discourse.org/t/custom-excerpt-length-not-working-for-me/284100 "2023-11-01T10:57:39Z")\
**Posts on this page:** 1\
**Showing post:** 9

<div class="post-metadata">

**Author:** ![simon](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/simon/32/339122_2.png) [@simon](https://meta.discourse.org/u/simon)\
**Post date:** [November 2, 2023, 9:24pm UTC](https://meta.discourse.org/t/custom-excerpt-length-not-working-for-me/284100/9 "2023-11-02T21:24:00Z")

</div>

> [@Petr\_Mišák](#):
>
> any ideas how to fix it?

The LnkBio plugin has a function that hooks into the `'wp_insert_post'` action. That function calls `unset($post->post_content)` on the WordPress `$post` object. Theoretically, this shouldn’t unset the post’s `post_content` attribute outside of the LnkBio function, but when I test this locally (mocking the LnkBio plugin’s API calls), the call to `unset($post->post_content)` is unsetting the post content for the [WP Discourse](https://github.com/discourse/wp-discourse) plugin here: [wp-discourse/lib/discourse-publish.php at main · discourse/wp-discourse · GitHub](https://github.com/discourse/wp-discourse/blob/main/lib/discourse-publish.php#L106).

This only happens when posts are published with the Classic Editor. If posts are published with the Block Editor, the post content is available to the [WP Discourse](https://github.com/discourse/wp-discourse) plugin. I’m assuming this is because posts published with the Block editor are published via a REST request.

Note that I’m running into the issue of no content being published to Discourse both when I set a custom excerpt length and when I select the [WP Discourse](https://github.com/discourse/wp-discourse) “Use Full Post Content” option.

The easiest fix would be to switch over to using the Block editor.

Another option would be to contact LnkBio and tell them about the issue. They could fix this by finding a safer way of parsing the post content for their API request:

```php
function lnkbio_api_sync($post_id, $post, $update) {
	unset($post->post_content);
	if ($post->post_status === 'publish') {
		if (!get_option('lnkbio_id') || !get_option('lnkbio_secret')) {
			return;
		}
		// url set to `example.com` for testing without a lnkbio account
		wp_remote_post(
			'http://example.com',
			[
				'blocking' => false,
				'body' => [
					'ACTION' => 'WP_sync',
					'post_id' => $post_id,
					'post' => json_encode($post),
					'id' => get_option('lnkbio_id'),
					'secret' => get_option('lnkbio_secret'),
					'permalink' => get_permalink($post),
					'is_pub'	=> true,
					'image' => get_the_post_thumbnail_url($post_id, 'full'),
					'group_id' => get_option('lnkbio_group'),
				]
			]
		);
	}
}

```

Edit: you could also just edit the LnkBio plugin’s code to remove the call to `unset($post->post_content);` and then finding a way of setting the appropriate values for the `$post` object that’s used here:

`'post' => json_encode($post)`

Generally editing plugins in this way is a bad idea, but it would work if you are very careful. Probably only do this if you have a way of testing your changes on a non-production site.

---

_[View the full topic](https://meta.discourse.org/t/custom-excerpt-length-not-working-for-me/284100)._
