I am trying to insert a custom tag after H3 tag with a certain class by inserting code into my theme's function.php file. Below is what I am doing but unable to achieve it.
If I have this, showing on a page currently:
<h3 class="title">TITLE HERE</h3>
<div class="desc">
I would like to insert a tag after h3 tag. Below is what I am trying to insert intp my theme functions.php file:
echo '<h3 class="title">TITLE HERE</h3>
<a tooltip="This is a test">TEST</a>
<div class="desc">'
As a result, I am just getting 'TEST' on the top of the page instead of showing it after the h3 tag.
Can you try this first.
Add **<div style="clear:both;"></div>** after your closing </h3> tag
OR
I think you are creating shortcode in function.php file. If you directly echo in your function then this problem will arise. First you assign the value to variable which you want to echo and then return this variable.
Eg:
function my_fun(){
$text='<h3 class="cuzd-title"> TITLE HERE</h3> <div style="clear:both;">
</div> <a data-tooltip="THIS IS TEST">TEST</a>';
return $text;
}
add_shortcode( 'shortcode_name', 'my_fun' );
now where you want these to be display just use
echo do_shortcode('[shortcode_name]');
Related
I'm looking to change heading tag (currently H5) for product categories displaying on home page. These categories are displayed on home page by using an element named ux_product_categories on Flatsome theme.
It seems to be a shortcode. So I looked at product_categories.php file in wp-content/themes/flatsome/inc/shortcodes.
Indeed, I found H5 heading tag, however, when I change it (by putting the modified file with the same path in child theme)... Nothing happens, product categories have still H5 heading tag.
What do I missed ?
Here's the code I changed (replacing "h5" by "p") :
<div class="box-text <?php echo implode(' ', $classes_text); ?>" <?php echo get_shortcode_inline_css($css_args); ?>>
<div class="box-text-inner">
<h5 class="uppercase header-title">
<?php echo $category->name; ?>
</h5>
I have a div in header.php like this:
<div id="myDiv">Some text</div>
I want to add a class to that div from a template/template-part file based on data/logic i have in the template file. I tried creating filter like this:
add_filter( 'toggler_class', 'my_class_add',10, 1 );
function my_class_add($class='') {
echo 'class="'.$class.'"';
}
And in header.php i had:
<div id="myDiv" <?php apply_filters('toggler_class', ''); ?> >Some text</div>
Which prints:
<div id="myDiv" class="">Some text</div>
This works; but now I want to modify that filter in a template file so that the div gets a new class:
<div id="myDiv" class="myNewClass">Some text</div>
How can I achieve this?
trying to use <?php the_category( ' ' ); ?> to put in my category from my wordpress post.
within the loop html
<a href='<?php the_permalink(); ?>'>
<section id="post-<?php the_ID(); ?>" class="..">
<div>
<?php the_category( ' ' ); ?>
<?php the_title( '<h1>', '</h1>' ); ?>
</div>
</section>
</a>
Problem is that having the category php the section div's seems to get pulled out of the link (output has section outside link code.
Not having the category code it works perfectly.
You have an issue in your HTML: you have a <a> tag (inline element) with inside block type elements (like <div> and <section>).
Take a look at this page in order to properly understand the difference between inline and block elements.
While using the_category(), you are going to displays a link to the category or categories a post belongs to, so you are also placing a <a> tag inside another <a> tag.
Because you want just display the categories' names, you can use the following code
foreach((get_the_category()) as $category){
echo $category->name."<br>";
}
Review your formatting and everything will be work as expected.
i want to get the wordpress title post to a span tag.
i use the code below with the_title() in span tags:
<?php echo '<div>
<img src="image.jpg"/>
<h2><span>'.the_title().'</span>
</h2></div>'; ?>
but the title is show in a tag P, the result is:
<p>TITLE_OF_THE_POST_IS_SHOW_HERE
<div>
<img src="image.jpg"/>
<h2><span></span>
</h2></div>
in result, the span tags is empty, how do insert the title in the span tag?
I would advice changing this
<?php echo '<div>
<img src="image.jpg"/>
<h2><span>'.the_title().'</span>
</h2></div>'; ?>
to something like this
<div>
<img src="image.jpg"/>
<h2>
<?php the_title( '<span>', '</span>' ); ?>
</h2>
</div>
the php the_title function see documentation Here accepts parameters so you can define the parent tag <span> inside of the wordpress function the_title().
Keep in mind that the_title shows the current post title. If you want to get a title from another post you can use get_the_title( post = 3 ) as Mark B mentioned above.
I have a PHP page that is pulling data from a MySQL table. One field (content) contains HTML to populate on the page. When trying to insert the record inside of a paragraph tag, the result starts and ends with a paragraph tag, but does not insert correctly as a child element, but as a sibling. Can anyone see the issue here?
HTML/PHP
<?php
foreach ($pages as $page) {
?>
<div class="slide" id="about-content">
<h1 class="pic-title"><?=$page->title;?></h1>
<p class="pic-caption overlay">
<?=$page->content;?>
</p>
</div>
<?php
}
?>
Output HTML:
<div class="fp-tableCell" style="height:419px;">
<h1 class="pic-title" style="margin-left: 25px;">Splash Page 2</h1>
<p class="pic-caption overlay" style="display: block;">
</p>
<p>dfajdfn<strong>akdjfnas</strong></p>
<p></p>
</div>
MySQL Data:
Title: Splash Page 2
Content: <p>dfajdfn<strong>akdjfnas</strong></p>
I can't seem to trace this one. Thanks!
That's to be expected, you're inserting a <p> inside another <p>. You can NOT nest paragraphs, and starting a new paragraph while inside a paragraph will terminate the earlier one.
e.g.
<p>foo
<p>bar
<p>baz
will internally generate
<p>foo</p>
<p>bar</p>
<p>baz</p>
In the DOM tree.
You should probably switch to using <div> instead:
<div class="pic-caption overlay">
^^^---
<?=$page->content;?>
</div>
^^^