最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

plugin development - Including content into an add_shortcode() function

programmeradmin2浏览0评论

my_html.php

<?php 

global $wp;
$op = get_option( 'mcc_d' );
$post_title = get_the_title();

isset( $this->op['mcc_d_text'] ) ? $mcc_d_text = $this->op['mcc_d_text'] : $mcc_d_text = '';

$html = '<div id="mcc_d_content">';
    $html .= 'some content';
$html .= '</div>';

And this is the shortcode.php file:

<?php
if ( ! defined( 'ABSPATH' ) ) {exit;}

include( PLUGIN_PATH . 'parts/my_html.php' );

function mcc_d_shortcode() {
    global $html;
    return $html;
}

add_shortcode( 'mcc_d_content', 'mcc_d_shortcode');

What doesn't work here is the shortcode output ($html), it's empty even when I make $html global (which what I'm trying to avoid)... what am I doing wrong here?

发布评论

评论列表(0)

  1. 暂无评论