Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
250 views
in Technique[技术] by (71.8m points)

php - Yoast Plugin Won't Detect Content from Shortcode in a Custom Plugin

I have created a pretty simple shortcode that contains html and php and wrapped it between the following code and used the shortcode inside a WordPress post. I went ahead to create custom plugin for which contains the shortcode.

I am having a challenge whereby the Yoast plugin is unable to detect the content of the shortcode. I know the shortcode is working perfectly, it's just that Yoast won't pull the right word count. The shortcode really contains a basic select query that fetches data from the database.

I found an article that mentioned Yoast only detects content that goes into the default WordPress editor and may not detect content from themes and plugins unless the developer adds the functionality. I'm the one doing this even as I learn.

The shortcode template I'm using:

function test_shortcode() {

    ob_start();

    ....
    
    return ob_get_clean();
}

add_shortcode( 'myshortcd', 'test_shortcode' );

Is there some code I need to add to the basic shortcode to get this to work?

Thanks.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

This is not something that is super easy to do because it requires tapping in to Yoast's javascript API. Here is the article explaining how to do it:

https://developer.yoast.com/customization/yoast-seo/adding-custom-data-analysis/

Yoast used to have a backend hook for this, but now it's all handled on the frontend.

An alternative approach would be to use a third-party service that scrapes the content as its rendered, which ultimately is going to give you better content analysis anyway. They aren't always cheap services though. Here's one our SEO team uses:

https://www.clearscope.io/


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...