snipt

Ctrl+h for KB shortcuts

PHP

WordPress template tag to display the name/title of PARENT page.

1
2
3
4
<?php
$parent_title = get_the_title($post->post_parent);
echo $parent_title;
?>

Description

Template tag to display the name/title of parent page.
https://snipt.net/embed/c8c2347c8a3ad9b9ddfb265764347707/
/raw/c8c2347c8a3ad9b9ddfb265764347707/
c8c2347c8a3ad9b9ddfb265764347707
php
PHP
5
2019-08-25T14:26:25
True
False
False
May 05, 2016 at 12:13 PM
/api/public/snipt/146151/
wordpress-template-tag-to-display-the-nametitle-of-parent-page
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a> <a href="#L-2">2</a> <a href="#L-3">3</a> <a href="#L-4">4</a></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a><span class="cp">&lt;?php</span> </span><span id="L-2"><a name="L-2"></a><span class="nv">$parent_title</span> <span class="o">=</span> <span class="nx">get_the_title</span><span class="p">(</span><span class="nv">$post</span><span class="o">-&gt;</span><span class="na">post_parent</span><span class="p">);</span> </span><span id="L-3"><a name="L-3"></a><span class="k">echo</span> <span class="nv">$parent_title</span><span class="p">;</span> </span><span id="L-4"><a name="L-4"></a><span class="cp">?&gt;</span><span class="x"></span> </span></pre></div> </td></tr></table>
wordpress
1
2
3
4
5
6
7
--- 
+++ 
@@ -0,0 +1,4 @@
+<?php
+$parent_title = get_the_title($post->post_parent);
+echo $parent_title;
+?>