I'm trying to insert a widget into a shortcode that I'm storing in my footer.php file...
<?php
echo do_shortcode( '[accordion_full_width title="upcoming events" full_width="yes" background_color="#68676b"]' .
dynamic_sidebar( 'footer_contents' )
. '[/accordion_full_width]'); ?>
...and it renders out the widget first, followed by the shortcode.
If this is a problem with using the dynamic_sidebar function inside of the do_shortcode, I'd think it just wouldn't spit the widget out, but it does. In the wrong place.
Does anybody have anything?
Add this Code in Your Template
<?php if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar('Name of Widget') ) : ?>
<?php endif; ?>
Related
I want to extract the images contained in a gallery block while maintaining their correct order. Since get_children() and get_attached_media() do not seem to register when the image order is changed in wp-admin, I'm trying to use get_post_gallery() instead.
My problem is that the function returns false, even though the post does have a gallery.
I tried both the example and the plain usage from Codex. Currently, my entire single.php looks like this:
<?php
get_header(); //html head etc
if (have_posts()): while (have_posts()) : the_post(); //the loop
if ( get_post_gallery() ) :
echo get_post_gallery();
else :
echo (the_ID() . " has no gallery.");
endif;
endwhile;
endif;
?>
… which results in "ID has no gallery" every time.
However, the output of print_r($post->post_content); does include the following, which seems to confirm that there is in a fact a gallery:
<!-- wp:gallery {"ids":[80,81,82]} -->
<figure class="wp-block-gallery columns-3 is-cropped">
<ul class ="blocks-gallery-grid">
<!-- … -->
I'm also attaching a screenshot from wp-admin to make sure I don't misunderstand what constitutes a gallery.
get_post_gallery() works only for native galleries which have been created in classig WYSIWYG editor. You can find more about it there. Hovewer, if you create Gallery via Gutenberg, it create the whole HTML code instead of classic editor gallery which create shortcode like this: [gallery ids="400097,400052,400051"] . Functions get_post_gallery(), get_post_galleries() and get_post_gallery_images() works only on classic galleries added via native shortcode.
Are you only trying to display the gallery block as opposed to all content? If so, maybe try this?
<?php
get_header(); //html head etc
if (have_posts()): while (have_posts()) : the_post(); //the loop
if (has_block('gallery', $post->post_content)) {
echo 'yes, there is a gallery';
$post_blocks = parse_blocks($post->post_content);
foreach ($post_blocks as $post_block){
if ($post_block['blockName'] == 'core/gallery'){
echo do_shortcode( $post_block['innerHTML'] );
}
}
}
// if there is not a gallery block do this
else {
echo 'no gallery';
}
endwhile;
endif;
get_footer();
?>
I got some inspiration from reading this post btw.
I have an ACF true or false based if the condition to show a section based on the mentioned code. it works correctly on the front page/homepage of WordPress. but it doesn't work in the inner pages, not getting the values of the field and I use this code in footer templates.
its a WordPress site with the latest version. and the code is in the footer template
<?php
$show_company_info = get_field( "show_company_info", get_the_ID() );
if($show_company_info ):
?>
<section class="company">
<div class="container">
<?php if ( is_active_sidebar( 'company-info-widget' ) ) : ?>
<?php dynamic_sidebar( 'company-info-widget' ); ?>
<?php endif; ?>
</div>
</section>
<?php endif; ?>
if we checked the ACF true/fields condition in any page it will show the section otherwise not. but it actually works in homepage only
Assuming that you have created a field in a Home Page.
So, to retrieve the home page field you need to do like this :
$frontpage_id = get_option( 'page_on_front' );
$show_company_info = get_field( "show_company_info", $frontpage_id );
if ( $show_company_info ) {
//Your code
}
I've recently purchased the events plus Wordpress plugin from http://wpeventsplus.com/ and am trying to get the calendar to show up on a template page. However, the shortcode [PLUS_CALENDAR] is not working on the template page I wrote. Here's my entire code for that page:
<?php
/*
Template Name: page-registration
*/
?>
<?php get_header(); ?>
<?php if ( have_posts() ) {
while ( have_posts() ) {
the_post();
//
// Post Content here
//
} // end while
} // end if
?>
<?php get_footer(); ?>
My background is in HTML and CSS, and I'm not familiar with php much at all. I should also mention that my site is WP Theme converted from a normal HTML site, making it a little harder to work with plugins, as the code was not converted in a very clean way to php. I'm guessing I have a mistake, or a few, in my code, but I have no idea where to start looking, I'd appreciate any help. Thanks.
You can execute a shortcode in a WordPress PHP file this way:
<?php echo do_shortcode('[PLUS_CALENDAR]'); ?>
Details: https://developer.wordpress.org/reference/functions/do_shortcode/
So your code becomes:
<?php
/*
Template Name: page-registration
*/
?>
<?php get_header(); ?>
<?php if ( have_posts() ) {
while ( have_posts() ) {
the_post();
//
// Post Content here
echo do_shortcode('[PLUS_CALENDAR]');
//
} // end while
} // end if
?>
<?php get_footer(); ?>
In WooCommerce, my theme displays descriptions for categories, archives, etc. I am trying to strip HTML from one of them, which is the WooCommerce Archive Description. The description is called with:
<?php endif; ?>
<?php do_action( 'woocommerce_archive_description' ); ?>
<?php if ( have_posts() ) : ?>
I need to apply the wp_strip_all_tags function to the do_action... is that possible? I know this is wrong, but something like:
<?php do_action( wp_strip_all_tags('woocommerce_archive_description') ); ?>
You need to strip the tags in each of the functions attached to that action. Search your theme and plugins to find the functions. For instance, in woocommerce 2.0.20 there are two - woocommerce_taxonomy_archive_description and woocommerce_product_archive_description. Since those function declarations have a check to see if they exist, you could override them by adding your own with the same name in the theme.
What you could do is to replace:
<?php do_action( 'woocommerce_archive_description' ); ?>
with:
<?php echo $queried_object->description; ?>
I prefer to do it like this:
<?php echo '<h2 class="term-description">' . $queried_object->description . '</h2>'; ?>
Because I want to get rid of the paragraph tags surrounding the description and I want to replace the DIV whose class is "term-description" with an H2 and I'm fine to retain the original class.
Enjoy!
Kind Regards,
Mihai Bocsaru
I'm a bit new to this, but I researched this topic a bit online and can't seem to figure out what I'm doing wrong. So basically, I created a duplicate footer to call for the homepage. We use a marketing automation tool called Pardot and we don't want to track visits to the homepage. So I created a file in the footer folder next to "footer-default.php" called "footer-nopardot.php" that omits the code.
In the home.php file, I edit the bottom with
<?php
get_footer('nopardot'); ?>
But it appears the homepage is still calling the default footer. Any advice on what to do or what I'm doing wrong?
Thanks!
just add this to your home template:
<?php
if ( is_home() ) :
get_footer( 'nopardot' );
else :
get_footer();
endif;
?>
you can use this loop just replace the home or 404 by your page name where you want to display your footer:
<?php
if ( is_home() ) :
get_footer( 'home' );
elseif ( is_404() ) :
get_footer( '404' );
else :
get_footer();
endif;
?>
and since you are just changing your home page footer u can just do this
<?php
if ( is_home() ) :
get_footer( 'yourName' );
else :
get_footer();
endif;
?>
Make sure of the file name to be footer-yourName.php
and then call it as follow:
get_footer( 'yourName' );
hope that helps :)