A way to automatically install pages on theme install?

I got similiar situation where I needed to add page on theme activation and set it as homepage automatically. Here’s how I did it: add_action(‘after_setup_theme’, ‘mytheme_setup’); function mytheme_setup(){ if(get_option(‘page_on_front’)==’0′ && get_option(‘show_on_front’)==’posts’){ // Create homepage $homepage = array( ‘post_type’ => ‘page’, ‘post_title’ => ‘Home’, ‘post_content’ => ”, ‘post_status’ => ‘publish’, ‘post_author’ => 1 ); // Insert … Read more

Custom Image section in Customizer

So I did some research on the matter and I found a solution. Basically WordPress has this cool feature where you can call something called get_theme_mod so what I essentially did was add get_theme_mod inside my <img> src. So this is what I changed my <img> tag to after finding out about get_theme_mod: <img src=”https://wordpress.stackexchange.com/questions/215701/<?php … Read more

How to enqueue script if widget is displayed on page?

You should be able to call wp_enqueue_script() as part of your Widget output. Edit Quick-and-dirty, using the bare-bones Widgets API class example: <?php class wpse48337_Widget extends WP_Widget { public function __construct() { // widget actual processes } public function form( $instance ) { // outputs the options form on admin } public function update( $new_instance, … Read more

CSS classes for theme

There are many CSS classes generated by WordPress, depending on context. The Theme Review Guidelines include the following, WordPress-generated CSS classes: Alignment Classes: .aligncenter .alignleft .alignright Caption Related Classes: .wp-caption .wp-caption-text .gallery-caption Post Classes: .sticky Comment Classes: .bypostauthor Then, there are the body classes generated by body_class(). Then, there are the post classes generated by … Read more

Should we use get_template_part() in functions files instead of include_once?

Your functions.php doesn’t create output, so you should use locate_template(). Example: locate_template( ‘php/functions.nav-menu.php’, TRUE, TRUE ); You’ll find this function in wp-includes/theme.php. The first parameter is the file path relative to the theme root, the second tells WordPress to load it (or not), and the third to load it just once. Now a child theme … Read more

What is the difference between wp_register_sidebar_widget and register_widget?

wp_register_sidebar_widget() is part of the old widgets API. Sidebar widgets used to be built procedurally … in a non-reusable fashion (i.e. you could only ever have one of each). register_widget() was introduced with the new Widgets API and takes an object/class as an input rather than actual widget parameters. WordPress can instantiate as many copies … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)