I have a Wordpress website with Virtue theme. And I want the page titles on every page (except the homepage) give a typing effect. I installed this plugin and it wrotes I just need to insert this code:
<?php echo do_shortcode( '[typed string0="Projects" typeSpeed="40" startDelay="0" backSpeed="40" backDelay="500"]' ) ?>
into the .php file in the theme where I need it. I just need to change the "Projects" to the actual page's title.
Where should I insert it?
You should concatenate that string with get_the_title():
<?php echo do_shortcode( '[typed string0="' . get_the_title() . '" typeSpeed="40" startDelay="0" backSpeed="40" backDelay="500"]' ) ?>
I could find the solution! I had to insert it in page-header.php like:
<?php echo do_shortcode( '[typed string0="'. apply_filters('kadence_page_title', kadence_title() ) .'" typeSpeed="40" startDelay="0" backSpeed="40" backDelay="500"]' ); ?>
Related
recently i install wordpress Themeforest VideoTube Theme. But when i use codecanyon Social Locker plugin, then facing this issue. My wordpress theme only support do_shortcode
My short code is...
[sociallocker id="2378"] [/sociallocker]
and i want to put this code in the middle position of my short code.
<div class="player player-small <?php print apply_filters( 'aspect_ratio' , 'embed-responsive embed-responsive-16by9');?>">
Kindly help me... how can i to do this? What query i set to in my wordpress theme functions.php file?
You can use do_shortcode like this way,
$text_to_be_wrapped_in_shortcode = '<div class="player player-small <?php print apply_filters( 'aspect_ratio' , 'embed-responsive embed-responsive-16by9');?>">';
echo do_shortcode( '[sociallocker id="2378"]' . $text_to_be_wrapped_in_shortcode . '[/sociallocker]' );
This should work,
$text_to_be_wrapped = "<div class='player player-small ".apply_filters( 'aspect_ratio' , 'embed-responsive embed-responsive-16by9')."'";
echo do_shortcode( '[sociallocker id="2378"]' . $text_to_be_wrapped . '[/sociallocker]' );
I am trying to show the amount of posts each users on my WP site has posted.
Currently the code I have is:
<?php
$author_id = the_author_meta('ID');
echo count_user_posts('$author_id');
?>
As you can see I am storing the author ID in $author_id and running that in the count_user_posts() echo.
When I run the to strings separately it works however when, I combine them as above it doesn't.
Any ideas?
Regards,
You should use get_the_author_meta for this kind of purposes.
$author_id = get_the_author_meta('ID');
echo count_user_posts($author_id);
the_author_meta should be used only for echoing stuff.
Try to use it like this :
<?php
$author_id = the_author_meta('ID');
echo count_user_posts($author_id); // remove quotes
?>
Hope it works for you now.
I found you need to add your post, page or your_custom_post_type for it to work successfully.
<?php echo 'Posts made: ' .(count_user_posts(get_the_author_meta('ID'),'your_custom_post_type') ); ?>
// or multiple post types
<?php echo 'Posts made: ' . count_user_posts( get_the_author_meta('ID'),['job', 'featured_job', 'free_job'] ); ?>
It does what I want it to do, displays a certain category of posts in a column on a page. Right now its just the title, but I want to link that title and the permalink section isnt working, or rather the href.
[php]
// The Query
$the_query = new WP_Query( 'cat=3' );
// The Loop
if ( $the_query->have_posts() ) {
echo '<ul style="list-style:none;">';
while ( $the_query->have_posts() ) {
$the_query->the_post();
echo '<li>' . '<a href="the_permalink();">' . get_the_title() . '[/a]'. '</li>';
}
echo '</ul>';
} else {
// no posts found
}
/* Restore original Post Data */
wp_reset_postdata();
[/php]
It links to subdomain.domain.com/site/the_permalink(); instead pulling the permalink for that post and linking to it.
the_permalink(); return to echo your link.
You need to return only string. For this you can use get_the_permalink($post->ID);
Because your permalink function is inside of echo function.
When you enter the a-tag you start with HTML, if you close it you change to BBCode.
Fatih is right, you need to use get_permalink function. Since you're inside the loop, you don't need to specify the parameter ($post->ID).
Also, you need to switch back to PHP (that is your main problem) as you did with get_the_title function. There are multiple syntax issues with your code (brackets!).
The line should go like this:
echo '<li>' . get_the_title() . '</li>';
Learn the difference between echo and return in (not only) PHP functions!
I am building a wordpress ecommerce template with Cart66 plugin. Using a Cart66 shortcode inside a php template page, I would like to generate the Post ID inside the shortcode. Can someone please help and tell me if this is possible. Here is the code that I am using.
<?php echo do_shortcode("[add_to_cart item=\". the_ID() .\" quantity=\"user:1\"]"); ?>
This code will lay inside loop-single.php and above
Thank you!
#silent almost had it, but it should be get_the_ID() and not the_ID() since the later one echos it out, so try:
<?php echo do_shortcode("[add_to_cart item=\"". get_the_ID() ."\" quantity=\"user:1\"]"); ?>
The right line should be:
<?php echo do_shortcode("[add_to_cart item=\"". the_ID() ."\" quantity=\"user:1\"]"); ?>
simpler correct answer:
<?php echo do_shortcode('[add_to_cart item="'. get_the_ID() .'" quantity="user:1"]');?>
This may be a simple one for you PHP experts out there. I need to give a certain <h1> to a post else show the page/post title.
I have this so far, it works if it is on a single post page, but when I am on a different page it just shows 'the_title' instead of the page title. I think its basically about calling a php function inside an already open php tag, if that makes sense. Here is the code:
<?php
if ( is_single() ) {
echo 'News';
} else {
echo the_title();
}
?>
The Wordpress tag for the page title is <?php the_title ?>
You are echoing 'the_title' as a string, you need to actually execute the function like so:
if ( is_single() ) {
echo '<h1>News</h1>';
} else {
echo '<h1>' . the_title() . '</h1>';
}
Note the closing quote to halt the string, and the . to concatenate the WordPress function the_title(), and then another to join the ending <h1> tag.
A cleaner way is to add the tags inside the function itself, like this:
<?php the_title('<h1>', '</h1>'); ?>
No need for 'echo'.