admin管理员组

文章数量:1429082

I am building a Wordpress/Woocommerce site, and developing a plugin for it.

In the plugin I am including some PHP html templates and hooking them into Wordpress in various ways.

Is there a way to visually compose and store these page snippets/sections somehow so that they can be viewed and edited in admin, through a visual composer?

I am envisioning something like Wordpress' page designer/editor, except just for page sections/snippets.

Thanks in advance!

I am building a Wordpress/Woocommerce site, and developing a plugin for it.

In the plugin I am including some PHP html templates and hooking them into Wordpress in various ways.

Is there a way to visually compose and store these page snippets/sections somehow so that they can be viewed and edited in admin, through a visual composer?

I am envisioning something like Wordpress' page designer/editor, except just for page sections/snippets.

Thanks in advance!

Share Improve this question edited May 5, 2019 at 13:30 Kerry Randolph asked May 4, 2019 at 17:20 Kerry RandolphKerry Randolph 993 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

I found that this can be done simply by using Wordpress' Page editor. Nothing else is needed:

  1. Compose the content in Wordpress' Page editor
  2. Save (but don't publish)
  3. In your code, retrieve the saved content

By ID:

$id=47;
$post = get_post($id);
$content = apply_filters('the_content', $post->post_content); 
echo $content;

Or by page title:

$title = 'page title';
$page = get_page_by_title( $title );
$content = apply_filters('the_content', $page->post_content); 
echo $content;

Note that apply_filters is used in case there is a plugin somewhere that wants to "apply filters" to the_content - it's good for forwards compatibility.

本文标签: pluginsIs there a visual editor specifically for page snippetssections