Customize Consent Preferences

We use cookies to help you navigate efficiently and perform certain functions. You will find detailed information about all cookies under each consent category below.

The cookies that are categorized as "Necessary" are stored on your browser as they are essential for enabling the basic functionalities of the site. ... 

Always Active

Necessary cookies are required to enable the basic features of this site, such as providing secure log-in or adjusting your consent preferences. These cookies do not store any personally identifiable data.

No cookies to display.

Functional cookies help perform certain functionalities like sharing the content of the website on social media platforms, collecting feedback, and other third-party features.

No cookies to display.

Analytical cookies are used to understand how visitors interact with the website. These cookies help provide information on metrics such as the number of visitors, bounce rate, traffic source, etc.

No cookies to display.

Performance cookies are used to understand and analyze the key performance indexes of the website which helps in delivering a better user experience for the visitors.

No cookies to display.

Advertisement cookies are used to provide visitors with customized advertisements based on the pages you visited previously and to analyze the effectiveness of the ad campaigns.

No cookies to display.

WordPress Snippet

ワードプレスをカスタマイズしよう

投稿内でショートコードを実行する

WordPressのコアの機能では、captionショートコードや、gallaryショートコードが、ビジュアルエディタで実行されますが、テーマやプラグインで手作りしたショートコードは、ショートコードそのものが表示されるだけで、実際に投稿するとどのように見えるのか プレビューしないと見ることが出来ません。

ビジュアルエディタでも、反映してくれるといいななどと考えていました。

ただ、実際にビジュアルエディタで、ショートコードを実行すると、ショートコードによってはエディタ画面で正しく表示できない事も容易に予想されるため、
実行するショートコードを決めておいて、条件に合う場合には、実行するといったアイディアをメモに残します。

以下の例では、[lorem],’[lorem lang=”ja”]という自作のショートコードを指定していますが、その辺りは、何か簡単なショートコードを作って試してください。

([lorem]は、ダミーテキストを書き出すショートコードです)

add_filter( 'format_for_editor', 'function_name' );

function function_name( $return_value ) {
	
	$reflect_items= array('[lorem]','[lorem lang="ja"]' );
	
	foreach( $reflect_items as $item ) {
		
		$shortcode[]= do_shortcode( $item );
	}
	
	return str_replace( $reflect_items, $shortcode, $return_value );
}

format_for_editor

その2、ショートコードをエディタ内ですべて実行

add_filter( 'format_for_editor', 'function_name' );
 
function function_name( $return_value ) {
	$content= get_post_field('post_content', get_the_ID());
	
	return do_shortcode( $content );
}

[emulsion_relate_posts]