🔥码云GVP开源项目 12k star Uniapp+ElementUI 功能强大 支持多语言、二开方便! 广告
【6.shortcode】 shortcode适合应用在post/page中需要在后台修改的特定部分。 在function.php上加上: `require get_parent_theme_file_path( '/inc/shortcode.php' );` 在shortcode.php上加上: ~~~ <?php function dwwp_sample_shortcode1(){ return ' <section id="gallery-1" class="gallery-1 page_section"> <div class="container"> <div class="row"> <div id="isotope-gallery-container"> '; } add_shortcode('start', 'dwwp_sample_shortcode1'); function dwwp_sample_shortcode2($template, $content=null){ $template=shortcode_atts( array( // image_url不能大写 'image_url' => 'Default title', 'demo_url' => '12345678', 'title_name' => '12345678' ), $template ); return ' <div class="col-md-4 col-sm-6 col-xs-12 gallery-item-wrapper artwork creative"> <div class="gallery-item"> <div class="gallery-thumb"> <img src=" ' . $template['image_url'] . ' " class="img-responsive" class="img-responsive" alt="1st gallery Thumb"> <div class="image-overlay"></div> <a href=" ' . $template['image_url'] . ' " class="gallery-zoom"><i class="fa fa-eye"></i></a> <a href=" ' . $template['demo_url'] . ' " target="_blank" class="gallery-link" target="_blank"><i class="fa fa-link"></i></a> </div> <div class="gallery-details"> <div class="editContent"> <h5><a href=" ' . $template['demo_url'] . ' " target="_blank"> ' . $template['title_name'] . ' </a></h5> </div> </div> </div> </div> '; } add_shortcode('template_code', 'dwwp_sample_shortcode2'); function dwwp_sample_shortcode3(){ return ' </div> </div> </div><!-- /.container --> </section> '; } add_shortcode('end', 'dwwp_sample_shortcode3'); ~~~ 在post/page上加上: ~~~ [start] [template_code image_url="https://s.tmimgcdn.com/scr/62400/julie-bernerro-photographer-portfolio-responsive-wordpress-theme_62452-original.jpg" demo_url="https://www.templatemonster.com/wordpress-themes/62043.html" title_name="Template 1"] [end] ~~~ 效果如下: ![](https://box.kancloud.cn/927e239b232a2219a71bc9424497f8d7_471x348.jpg) 【在php文件显示shortcode】 `<?php echo do_shortcode('[name_of_shortcode]'); ?>` 参考: https://developer.wordpress.org/reference/functions/do_shortcode/