Wordpress widgets not displaying on custom theme - wordpress

I built a custom wordpress theme, and I also built a custom widget sidebar (so widgets are enabled), I can see the title of the widget, but the content is not showing. For example I'm using a poll widget, the title is exactly as I've set it, but the content is completely blank.
In the header the scripts for the plugin are loaded, but again there is no content. I tried multiple plugins, and they all do the same thing. I also attempted this with using do_shortcode() and again, no content. So I am stumped.
I have also tried getting support on the wordpress forum, but I've never successfully gotten an answer to my query there.
My hope is that someone has had this same issue, and can point me to what the problem may be.
In the header, i've included the following information:
<html <?php language_attributes(); ?>>
<meta charset="<?php bloginfo( 'charset' ); ?>" />
<?php wp_head();?>
<?php wp_meta();?>
<?php wp_print_scripts();?>
However again, no results. Google searches have also not pulled up anything about this being an issue. Here's the odd thing, I design all wordpress themes the same way, most of which are all hosted on the same server, and this is the only theme having this problem.
Also I've included my functions.php script for reference purposes.
<?php
function twentyten_widgets_init() {
register_sidebar( array(
'name' => __( 'Primary Widget Area', 'twentyten' ),
'id' => 'primary-widget-area',
'description' => __( 'Add widgets here to appear in your sidebar.', 'twentyten' ),
'before_widget' => '<div id="spacer">',
'after_widget' => '</div></div>',
'before_title' => '<div id="left_top">',
'after_title' => '</div><div id="left_bottom">',
) );
}
add_action( 'widgets_init', 'twentyten_widgets_init' );
add_filter( 'show_admin_bar', '__return_false' );
remove_action( 'personal_options', '_admin_bar_preferences' );
?>
EDIT **
I removed from the header as it was causing duplicate scripts in the header. So that is no longer an issue, however that did not resolve the issue and nothing has changed as a result of being removed.

From your code all your widget will look like:
<div id="spacer">
<div id="left_top">Title</div>
<div id="left_bottom">
CONTENT
</div></div>
You are using id's here (maybe you intend to use classes) here for your elements, like id="left_top". So adding more than one widget will give you a problem, see Can multiple different HTML elements have the same ID if they're different elements?, cause the id's should be unique.
You will maybe apply a css / javascript on one of these id's like
#left_bottom{display:none} this will explain why your content will be not shown independent of the widget you use.

Related

What default function need to be include in new wordpress theme

I am creating a wordpress theme from scratch.
I created my own page.php, header.php , footer.php, sinngle.php .
When i install any 3rd party plugin , it does not work but works on any third party themes.
Do i need to include any predefined wordpress API to make it work ?
Yes, there are several functions you need to add in your theme to make fullfledged WordPress theme.
First read this thoroughly. https://codex.wordpress.org/Theme_Development
Some important points:
In header.php, there should be wp_head() function call just before </head>
In footer.php, there should be wp_footer() function call just before </body>
You need to use WordPress loop properly. https://codex.wordpress.org/The_Loop
If you want to register Navigation, Sidebar, etc then it should be done in functions.php
Display your widget in your theme pages like this:
<?php if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar('header_sidebar') ) :
endif; ?>
You of course can replace the dynamic_sidebar above with the actual tag name of the 3rd-party widget you wish to integrate.
If you make your own widgets, register them in your functions.php
http://wpgyan.com/how-to-create-a-widget-area-in-wordpress-theme/
Example:
<?php
/**
* Register Widget Area.
*
*/
function wpgyan_widgets_init() {
register_sidebar( array(
'name' => 'Header Sidebar',
'id' => 'header_sidebar',
'before_widget' => '<div>',
'after_widget' => '</div>',
'before_title' => '<h2 class="rounded">',
'after_title' => '</h2>',
) );
}
add_action( 'widgets_init', 'wpgyan_widgets_init' );
?>

Add custom CSS to my Polylang widget and remove bullets - using WordPress

I am desperately trying to remove the bullets that appear in front of the flags. I am using WordPress and I've added this Polylang feature as a widget in my header. I tried to post a screenshot but I can't upload images yet.
I would also like to custom css this widget but I have tried everything I can think of and nothing is happening. Basically this is placed on the left side of my page when I want it on the right side. Here is the code I used in the my_functions php:
function my_widgets_init() {
) );register_sidebar( array(
'name' => __( 'Header Area', 'your-theme' ),
'id' => 'sidebar-2',
'description' => __( 'An optional widget area for your site header', 'your-theme' ),
'before_widget' => '<div id="%1$s" class="headwidget %2$s">',
'after_widget' => "</div>",
'before_title' => '<h3>',
'after_title' => '</h3>',) );
}
add_action( 'widgets_init', 'my_widgets_init' );
And here is the code used in header.php
<div class="span12" id="polylang-2">
<?php if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar('sidebar-2') ) : ?> <?php endif; ?></div>
I tried entering Custom CSS from the WP admin widgets panel, i have no idea how to code from here I guess cause nothing ever changes... I have already done a lot of customization to my site so I am ok with CSS, it's more finding where to make changes I have trouble with. And php is not my forte yet.
Thanks for all your help.
you can inject a custom class after widget class as shown in the code below:
'before_widget' => ''
now you can call the class myclass from style.css file present in your theme folder I hope you know how to remove the bullets in the css
you can locate your theme files from wp-content/themes/themename
.myclass {float:left;} /* to move it on the left */
.myclass ul {list-style:none;}
Moreover you dont require a div with the id polylang-2 since the div automatically comes from the above widget code.
and you can change the header.php code to
<?php dynamic_sidebar("sidebar-2");?>
OR
the next way around is if you want to use your existing code then add the following css in your style.css file inside your theme
#polylang-2 ul {list-style:none;}
Let me know if it solves your problem or not. Thanks

Default Image appears blank - Wordpress Theme Customization API

I want to make it possible for users of my theme to replace the banner through Theme Customization API. I have got it working, however, the default image appears blank and when I click "view page source" I get the following:
<img src=" " alt="banner" />
The default image shows up in the preview inside the API window, but not in the browser. The moment I upload a banner to replace the default banner with, it works perfectly. But I just can't get the default image to appear. Am I doing something wrong?
This is in my functions.php:
// Start New Section for Images
$wp_customize->add_section('customtheme_images', array(
'title' => _('Images'),
'description' => 'Change Images'
));
$wp_customize->add_setting('banner_image', array(
'default' => 'http://mywebsite.com/banner.jpg',
));
$wp_customize->add_control( new WP_Customize_Image_Control ($wp_customize, 'banner_image', array(
'label' => _('Change Banner'),
'section' => 'customtheme_images',
'settings' => 'banner_image'
) ));
And, this is inside my header.php:
<img src="<?php echo get_theme_mod('banner_image'); ?>" alt="banner">
And yes I have tripple checked the path of the default image, and it is corrent. Please help!
When using $wp_customize->add_setting('banner_image', array(
'default' => 'http://mywebsite.com/banner.jpg',
)); the default value is not saved into the database (until you save).
So you will have to use: <img src="<?php echo get_theme_mod('banner_image','http://mywebsite.com/banner.jpg'); ?>" alt="banner">
The problem you describe is some kind related to: https://wordpress.stackexchange.com/questions/129479/alternatives-to-handle-customizer-settings
I have the same situation here. The problem with the solution below:
<?php echo get_theme_mod('banner_image','http://mywebsite.com/banner.jpg'); ?>
I need the user to be able to delete the default image. This default image will only be used for the initial display of the theme. So I need a solution that when activating the theme, is already saved in the database.

Wordpress: functions.php Breaking Standard WP Functions

This issue is driving me crazy.
This morning, the Wordpress theme I'm creating included a very simple functions.php file, and my site worked properly. Today, I wrote a new function to iterate through categories and list certain posts, and that's the only change I made to functions.php.
After uploading the revised functions file to the server, I get a 500 error every time I access my site. I though, "OK, my new function broke something. I'll just remove it from functions.php and start over." However, after reverting to the original version of the file (the version that worked this morning), I'm still getting the 500 error.
If I remove functions.php from the server, my pages load (without their sidebars obviously, but they load). As soon as I upload the file again (same version that worked this morning), I get the 500 error.
I checked the error log, and I've found that, when I have functions.php on the server, Wordpress (or php more likely) can no longer find the get_template_directory_uri() function. I've done nothing to alter any of the standard Wordpress functions, and this only happens when I've got functions.php uploaded.
What might be causing functions.php to break the standard functions?
Here's my functions.php file:
<?php
/* *********************************************
* Create left-hand sidebar for single.php
*
* TODO: Finalize $sricks_single_left_sidebar.
* ********************************************/
$sricks_single_left_sidebar = array(
'name' => 'Left Sidebar',
'id' => 'lt-single',
'description' => 'This is the sidebar on the left side of the single.php template page.',
'before_widget' => '<!-- Left-Single Sidebar --><div class="lt-single">',
'after_widget' => '</div> <!-- End Left-Single Sidebar -->',
'before_title' => '<h1>',
'after_title' => '</h1>',
);
register_sidebar( $sricks_single_left_sidebar );
/* *********************************************
* Create header_search sidebar to be used on
* all pages
* ********************************************/
$sricks_header_search_sidebar = array(
'name' => 'Header Search',
'id' => 'header-search',
'description' => 'This is the search box in the page header.',
'before_widget' => '<!-- Header-Search Sidebar --><div class="header-search">',
'after_widget' => '</div> <!-- End Header-Search Sidebar -->',
'before_title' => '<h1>',
'after_title' => '</h1>',
);
register_sidebar( $sricks_header_search_sidebar );
?>
To find the cause of issues in WordPress when you get 500 level errors, a blank white screen, or any other strange or unexpected behavior, define the WP_DEBUG constant in wp-config.php.
Like this:
define( 'WP_DEBUG', true );
If you're developing or making changes to a site, it's usually a good idea to enable this feature until you're done editing. It can make it very easy to spot and correct mistakes that could otherwise vex for hours.
Thanks everyone, especially Spencer Cameron. It turns out I forgot the open and close parentheses in my new function's declaration. Wordpress reads functions.php before any of the built-in functions, so it just got stuck there.
When I submitted my code, I left out my new function because I had deleted everything from the body of the function; what could go wrong? Lesson learned...

Wordpress NextPage tag gives unwanted post pagination on home page

I'm building a Wordpress child theme on their stock twenty-eleven theme on a private test server.
I'm using <--nextpage--> to paginate long posts, and it works beautifully on my single post pages, but my problem is that it also shows the pagination on the home page excerpt for the paginated post, which I don't want. This happens even though the <--nextpage--> tag appears later than the <--more--> tag in my post.
Any ideas how to disable the post pagination on my home page while retaining on my single-post page?
Many thanks,
Donal
I haven't used the nextpage quicktag before but - from what I understand, at least - in order for a given post to understand that the quicktag needs to be converted to page links, you need to have wp_link_pages called somewhere within the given loop.
If that's the case, then you'll need to create a copy of the twentyeleven/content-single.php file and place that within your child theme.
On line 24 you should see this:
<?php wp_link_pages( array( 'before' => '<div class="page-link"><span>' . __( 'Pages:', 'twentyeleven' ) . '</span>', 'after' => '</div>' ) ); ?>
Try changing it to this:
<?php
if(!is_front_page())
wp_link_pages( array( 'before' => '<div class="page-link"><span>' . __( 'Pages:', 'twentyeleven' ) . '</span>', 'after' => '</div>' ) );
?>
This is untested, and quite honestly I've never put the nextpage tags to use before so I don't really know for certain if this will achieve what you want. But give it a try and let me know how it all works out.

Resources