将wordpress短代码添加到header.php

时间:2016-03-26 21:39:57

标签: php shortcode custom-wordpress-pages

我有6页,我想在每个页面的标题中添加一个不同的短代码。

有没有办法在页面标题h1之前添加图标短代码 - 但具体到每个页面名称或ID?

短代码是:

[icon enable_animation="true" color="Accent-Color" animation_speed="Slow" icon_size="" animation_delay="" image="basic_rss.svg"] 

我尝试将以下代码添加到page-sidebar.php,但是它将其直接放在标题的下方,而不是在其中。它也不是特定于页面的。

<?php echo do_shortcode('[icon enable_animation="true" color="Accent-Color" animation_speed="Slow" icon_size="" animation_delay="" image="basic_rss.svg"]'); ?>

2 个答案:

答案 0 :(得分:3)

将wordpress短码添加到header.php 使用Visual Composer短代码或任何可以使用的短代码

<?php
echo do_shortcode('[shortcode-here]'); 
?>

答案 1 :(得分:0)

您可以为每个页面创建不同的头文件使用get_header()将调用标准header.php模板文件;如果您将标题文件复制为header-one.php(请注意header之后的连字符),可以使用get_header( 'one' )调用它,然后相应地更改标题文件。