programing

워드프레스 테마에서 쇼트코드 사용

sourcejob 2023. 3. 10. 21:28
반응형

워드프레스 테마에서 쇼트코드 사용

워드프레스 3.3.1에 대한 새로운 테마를 처음부터 개발했는데 쇼트코드가 작동하지 않습니다.지금까지 검색해 본 결과, 쇼트 코드를 포함한 내용을 필터링 하는 것으로, 테마 고유의 장소에 추가된 필터 코드(쇼코드는 다른 테마로 동작하고 있습니다).그래서 제 질문은 다음과 같습니다: 일반적인 쇼트 코드 테마를 활성화하기 위한 코드는 무엇입니까?

단일 쇼트 코드를 실행하려면 다음 명령을 사용하여 실행합니다.

echo do_shortcode('[your_short_code]');

투고 내용에 쇼트 코드가 있는 경우는, 반드시, 다음과 같이 표시합니다.

<?php the_content();?>

또는

<?php echo apply_filters('the_content',$post_content);?>

또는

<?php echo apply_filters('the_content',$wp_query->post->post_content);?>

중요한 것은 "the_content()" 함수를 사용하지 않는 경우 이 행이 필요합니다.<?php echo apply_filters('the_content',$wp_query->post->post_content);?>여기서 두 번째 인수에는 표시할 게시물 내용의 변수를 넣어야 합니다.

테마의 내용을 변수에 저장한 후 두 번째 예를 사용해야 했습니다.마법처럼 작동했어.

$mycontent = ot_get_option('rightcontent');                     
echo apply_filters('the_content',$mycontent);

언급URL : https://stackoverflow.com/questions/9820190/enable-shortcodes-in-a-wordpress-theme

반응형