Gazi Gazi - 3 months ago 12
PHP Question

How to extract heading tags in php

in wordpress when I use

<?php the_title( '<h3>', '</h3>' ); ?>
it works
but if I have a different php output like this one
<?php echo $variable['custom_title_option']; ?>
how can I do the same as on the_title

also if I use a function like the below example:

function change_hading_titles() {
global $variable;
$heading_tag = $variable['custom_title']; //option name
if ($heading_tag == "h1") {
print '<h1>', '</h1>';
} elseif ($heading_tag == "h2") {
print '<h2>', '</h2>';
} elseif ($heading_tag == "h3") {
print '<h3>', '</h3>';
} elseif ($heading_tag == "h4") {
print '<h4>', '</h4>';
} elseif ($heading_tag == "h5") {
print '<h5>', '</h5>';
} elseif ($heading_tag == "h6") {
print '<h6>', '</h6>';
}
}
add_action('change_hading_titles', 'change_hading_titles');


is it possible to use
do_action( 'change_hading_titles' );
to change all my custom titles?
So, I mean to retrieve the function for closing
<?php echo $variable['custom_title_option']; ?>
with heading tags

Answer

Do you mean?

function getTag($tagName, $titleValue){

    return "<".$tagName.">".$titleValue."</".$tagName.">";

}

$tag = getTag("h1", "hello");
// $tag = <h1>hello</h1>

..If that is not what your after, please explain a little more clearly, am happy to help further. Either way, this would be a significantly more efficient way of doing that function.