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

Theme does not allow shortcodes

programmeradmin3浏览0评论

I'am createing my own theme. I want to use shortcodes but they're not working. If I enter them in a post I juste get the shortcode name whit brackets.

To display the code I use this function:

function post_content($page = null){
  //Define variables
  $page = get_post($page);
  $userData = get_userdata($page->post_author);
  $months_german = array(1 => 'Januar', 2 => 'Februar', 3 => 'März.', 4 => 'April', 5 => 'Mai', 6 => 'Juni', 7 => 'Juli', 8 => 'August', 9 => 'September', 10 => 'Oktober', 11 => 'November', 12 => 'Dezember');

  /*
  * Create page content
  */
  $html = '<div class="post-container">';
    //If the page has an featured image, display it
    if(get_the_post_thumbnail_url($page)){
      $html .= '<div class="header-image" style="background-image: url(\''.get_the_post_thumbnail_url($page).'\')"></div>';
    }
    //Start with content
    $html .= '<div class="content">';
      //General information (Title, date, author)
      $html .= '<div class="headline">';
        $html .= '<h1 class="title">'.$page->post_title.'</h1>';
        $html .= '<span class="time-author">'.date("j", strtotime($page->post_date)).' '.$months_german[date("n", strtotime($page->post_date))].' '.date("Y H:i", strtotime($page->post_date)).' |  von '.$userData->display_name.'</span>';
      $html .= '</div>';
      //Start maincontent
      $html .= '<div class="text">'.$page->post_content.'</div>';
    $html .= '</div>';
  $html .= '</div>';

  echo $html;
}

To create a shortcode I use this function:

function lorem_function(){
  return "<p>Lorem Ipsum dolor sit amet</p>";
}

add_shortcode('lorem', 'lorem_function');

if I execute the following function in the index.php file the shortcut works very well:

echo do_shortcode('[codeworks]');

I use both functions in the functions.php file.

Thank you for your support.

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论