Wordpress Shortcodes not rendering content (2 themes) - php

I've been having this problem for several weeks now, and would really like to get it resolved. I'm seeing issues like this all over the internet, however everyone is coming up empty.
I have 2 custom wordpress themes. One on a Linux (cPanel) Server, and one on a Windows (IIS) Server. Both of them have different custom themes, both of them are loaded with content. The two server php.ini's are identical (or as close as they can be). When I use the provided wordpress theme shortcodes are working fine. However when I take either of the custom themes, and make them active, shortcodes cease to work, they will show up on sidebars, and posts, but there is NO content, and by no content I mean: It shows the title of the widget, but not the actual widget itself.
I am quite literally at my wits-end here. This will be the 4th forum post in over a month on different sites, trying to get an answer. No one can help me anywhere. I'm hoping since I've had luck here with other issues, that maybe someone has seen this happen. Even custom shortcodes are not rendering.
I thought maybe it was because a script isn't called in the custom theme, but comparing the Wordpress TwentyTwelve theme and mine there are not any differences in the header file.
I've called wp_head(); and wp_meta();....So confused. Please help!!!
functions.php
<?php
function wpb_widgets_init() {
register_sidebar( array(
'name' => __( 'Main Sidebar', 'wpb' ),
'id' => 'sidebar-1',
'description' => __( 'The main sidebar appears on the right on each page except the front page template', 'wpb' ),
'before_widget' => '',
'after_widget' => '</div></div>',
'before_title' => '<div class="padding"><div class="top">',
'after_title' => '</div><div class="bottom">'));
}
add_action( 'widgets_init', 'wpb_widgets_init' );
apply_filters('the_content',get_the_content( $more_link_text, $stripteaser, $more_file ))
?>
sidebar.php
<?php if ( is_active_sidebar( 'sidebar-1' ) ) : ?>
<?php dynamic_sidebar( 'sidebar-1' ); ?>
<?php endif; ?>

Without code this is difficult to answer, but a good shot might be the use of get_the_content() instead of the_content() within your loop. Using get_the_content() will not apply the the_content filters. See:
If you use plugins that filter content (add_filter('the_content')), then this will not apply >the filters, unless you call it this way (using apply_filters):
<?php apply_filters('the_content',get_the_content( $more_link_text, $stripteaser, $more_file )) ?>
http://codex.wordpress.org/Function_Reference/get_the_content

Related

Adding search bar/form to a custom HTML navigation in Wordpress using get_search_form() function

My problem is that I built the navigation menu inside the 'top' section in the widgets area in WordPress (which is perhaps a mistake, as I can't add php in there).
Assume my menu is built this way:
<nav>
<div class="title-and-logo">...</div>
<div class="menu-links">...</div>
<div class="search-bar"> </div>
</nav>
The relevant css:
nav{
display: flex;
}
I need to add the search bar into the .search-bar div. My solution is to move the whole nav menu out of widgets area and into functions.php. (I am not very comfortable with PHP yet, that is why I am reluctant to mess around with it).
My question: is there a way to add the search bar generated by get_search_form() into the section with class="search-bar" without needing to remove my code somewhere that allows PHP?
Or: can I generate a normal search bar using HTML without needing to use the get_search_form() provided by WordPress? (but maybe the search function of WordPress is better?).
Any help is appreciated. You can suggest javascript and jquery fixes too.
You could create a custom widget area in your functions.php for your top nav like so:
<?php
/**
* Register our sidebars and widgetized areas.
*
*/
function my_custom_widget_area_init() {
register_sidebar( array(
'name' => 'Top Nav - Search',
'id' => 'top_nav_search',
'before_widget' => '',
'after_widget' => '',
'before_title' => '',
'after_title' => '',
) );
}
add_action( 'widgets_init', 'my_custom_widget_area_init' );
?>
Then you adjust your theme to display the widget:
<nav>
<div class="title-and-logo">...</div>
<div class="menu-links">...</div>
<?php if ( is_active_sidebar( 'top_nav_search' ) ) : ?>
<div class="search-bar"><?php dynamic_sidebar( 'top_nav_search' ); ?></div>
<?php endif; ?>
</nav>
Okay so I had a very specific problem which I doubt anyone else would have, but anyway, here is how I solved it:
I already had a plugin installed called 'widget shortcode' which transforms any widget I have into a shortcode that can be used inside text areas on the website.
A bit irrelevant but recall that I also had my navigation placed inside an HTML widget (but I was not using it as a shortcode, it was placed directly into the 'top widget area'.)
So all I had to do was get the shortcode of the search widget (as we have a search widget by default on Wordpress) and insert it inside the HTML of my Nav.
Problem: turns out we can't put shortcodes by default inside html widgets. Solution: place one line code in functions.php that would allow us to do so. Problem solved.

Wordpress custom sidebar template not active

I am working on a wordpress site (my first), where I want to use a specific sidebar for a specific page template. The sidebar is not the regular widget area, but a template (sidebar-2.php) that calls another template (boeking.php) of a form.
I used the default page.php and sidebar.php as a starting point, copied almost everything, and thus created a template for the page (reisbeschrijving.php) that calls sidebar-2 by using get_sidebar('2'). I also created a template sidebar-2.php:
It worked at first, but while I was working on another part of the website it stopped working all of a sudden. The page template works fine, but it doesn't load the sidebar-2, because the is_active_sidebar() returns false. However, I don't know why it returns false. When I call get_sidebar() (default) in reisbeschrijving.php, it does display sidebar.php, and is_active_sidebar() returns true. If I remove the if is_active_sidebar() clause, sidebar-2 displays just fine. both sidebar.php and sidebar-2.php are in the same folder (of the child theme).
Did I miss something? Should I register the new sidebar-2 template somewhere in the header or something? I know that this is the case for the custom dynamic sidebars with widget area's, but this is an altogether new template and I thought I wouldn't have to (I tried anyway, but to no avail).
Any hints on why is_active_sidebar returns 'false' on my second sidebar is greatly appreciated.
1st Register sidebar - functions.php
function my_custom_sidebar() {
register_sidebar(
array (
'name' => __( 'Custom', 'your-theme-domain' ),
'id' => 'custom-side-bar',
'description' => __( 'Custom Sidebar', 'your-theme-domain' ),
'before_widget' => '<div class="widget-content">',
'after_widget' => "</div>",
'before_title' => '<h3 class="widget-title">',
'after_title' => '</h3>',
)
);
}
add_action( 'widgets_init', 'my_custom_sidebar' );
Put this code in template
if ( is_active_sidebar( 'custom-side-bar' ) ) :
dynamic_sidebar( 'custom-side-bar' );
endif;
This will work 100%

WordPress: Adding Theme Support

I am trying to add the "Custom-Background" theme hook for a WordPress site.
In my functions file, the one for the theme folder, I added
add_theme_support( 'Custom Background', array (
'background-color' => '#000000',
'background-size' => 'cover'
) );
It seems to work because going into the WordPress Dashboard -> Appearances -> Background, I can add an image and have it shown in the Customizer space. But when I actually go to the page itself, it shows me a blank white background.
Is there an additional code I need to add to my '.php' files? There was a similar post previously here:https://wordpress.stackexchange.com/questions/259315/custom-background-image-not-showing-up
But I believe this does not work anymore, or maybe I'm doing my process wrong.
Based on the codex sample you need this format
$args = array(
'default-image' => 'https://cdn.pixabay.com/photo/2015/12/01/20/28/road-1072823__340.jpg',
'default-size' => 'cover',
);
add_theme_support( 'custom-background', $args );
Thank you for replying. I found out what the issue was with my code. It wasn't that my code was in an incorrect form, but I had forgotten to put a
<body <?php body_class();?>>
wherever I put my tag in.

Wordpress custom theme: Widget area not configurable in Customizer

I am currently developing a custom wordpress theme for my own website to use. My main concern is to include widget areas. I managed to include a widget area so that it is configurable from Appearance > Widgets and the result also shows up in the customizer preview and on the live website.
The only problem is that I am not able to configure the widgets from within the customizer. When I click on Widgets in the customizer, it only shows this message:
Your theme has a widget area, but this particular page doesn’t display it. You can navigate to other pages on your site while using the Customizer to view and edit the widgets displayed on those pages.
Well, since the under Appearance > Widgets configured widget is actually showing, my site seems to have a widget area. But I guess something is missing for the customizer to know that.
Here is the code registering the sidebar / widget area that I took from many similar tutorials:
<?php
function tgf_customize_register( $wp_customize ) {
//All our sections, settings, and controls will be added here
}
add_action( 'customize_register', 'tgf_customize_register' );
function tgf_widgets_init() {
register_sidebar(array(
'name' => 'Sidebar Widget',
'id' => 'main_sidebar_widget',
'description' => 'Widget Area',
'before_widget' => '<div class=”widget”>',
'after_widget' => '</div>',
'before_title' => '<h2>',
'after_title' => '</h2>',
) );
}
add_action( 'widgets_init', 'tgf_widgets_init' );
?>
This is the code displaying the sidebar:
<?php if ( is_active_sidebar( 'main_sidebar_widget' ) ) : ?>
<?php dynamic_sidebar( 'main_sidebar_widget' ); ?>
<?php endif; ?>
I also tried showing it with this code, but then the widget doesn't show on the site at all, even when I configure it from Appearance > Widgets:
<?php if ( is_active_sidebar( 'main_sidebar_widget' ) ) : ?>
<?php get_sidebar( 'main_sidebar_widget' ); ?>
<?php endif; ?>
Why can't I configure this widget from within the customizer?
This question WordPress theme creation : There are no widget areas on the page shown mentions the same error message in the customizer, but does not provide a solution that applies to my specific problem.
Since I couldn't find anything by researching this problem, I think I am missing something fundamental. Which could very well be, since I'm new to wordpress theme development and PHP. Thanks in advance!
Found out myself what none of the tutorials told me:
I have to add <?php wp_head() ?> at the start of the page and <?php wp_footer() ?> at the end of the page.
Wordpress seems to need these hooks in order to function properly.

Wordpress Theme Debug: Plugin sidebar causes original sidebar not to display

I have determined that my plugin code works perfectly fine in other themes, but in the theme: Magazinly, the sidebar plugin I wrote, causes the sidebar not to display. Through debugging, I've determined that the sidebars register, and two sidebar arrays are created, but one is not populated.
Here is the plugin code:
register_sidebar(array(
'name'=>'Bottom Widget Area',
'id'=> 'bottom-widget',
'before_widget' => '<aside class="widget %2$s">',
'after_widget' => '</aside>',
'before_title' => '<div class="block-title"><span>',
'after_title' => '</span></div>'
));
include 'add_bottom_bar.php';
This is add_bottom_bar.php:
// Register Bottom_Bar
function add_bottom_widget(){
echo '<div class=\'bottombar\'>';
if (!function_exists('dynamic_sidebar') || !dynamic_sidebar('bottom-widget')) :
endif;
echo '</div>';
}
add_action ('get_footer', 'add_bottom_widget');
// Register style sheet.
add_action( 'wp_enqueue_scripts', 'register_plugin_styles' );
// Register style sheet.
function register_plugin_styles() {
wp_register_style( 'custom_widget_final', plugins_url( 'custom_widget_final/css/bottom_bar.css' ) );
wp_enqueue_style( 'custom_widget_final' );
}
And here is the code for the sidebar in Magazinly:
http://pastebin.com/eJu7Wk3C
There's also this code that appears to use whatever this thing the theme creator called 'dinamic sidebar' to... well... I would imagine... render dynamic sidebars :
http://pastebin.com/T0LW3QTS
But, my guess is that this is the culprit: The Magazinly theme uses this sidebar loader, but it seems like serious overkill. I am guessing that the sidebar widget I'm registering, is disrupting this sidebar loader.
http://pastebin.com/jCtvjVqC
With all code presented, my next question is: what are my options? I need to add widget positions to three sites, all using the same theme, but preserve the sidebar. Presently, if I activate my plugin, the sidebar won't load, but the plugin works. If I deactivate the plugin, the sidebar returns.
Both are important, but I cannot modify the theme, and creating a child theme seems excessive. I'd prefer to debug this theme, and use widgets.
Here's what I have tried/tested:
Tested this plugin on four other WP sites. No issues. Sidebars render fine. Plugin works like a charm.
On problem site: wp_debug, set to true... throws no errors, but gives a warning for each of the theme's native sidebars (no id set, which is a pre 4.1 thing). To my knowledge, it does not affect anything.
I removed the include at the bottom, just to narrow down where the problem could be in my code. I determined that even when the css enqueue is disabled, or even if add_bottom_bar.php is not included, the theme's native sidebars still break. This makes it abundantly, totally clear to me that there is a register_sidebar conflict.
I've looked at the source when the plugin is activated, and when it is deactivated. I find after diffing the source, when the plugin is activated, the sidebars do not show in the source, so it is not a css/js thing, as far as I can tell.
What, if any workaround might there be for this? A widget would greatly improve workflow, but I'm beginning to consider that letting go of the sidebar/widget situation might be smarter.
Any hints, tips, or insight? I know my question is a bit general, but I've hit a brick wall, here, in trying to stay hands-off with this theme code.
Any help would be much appreciated! Thanks!
Ok. Figured it out.
add_action( 'widgets_init', 'bottom-widget' );
Needed to initialize the widget right after registering the sidebar.

Categories