Posts

Showing posts with the label theme

To use WordPress's wp_delete_user function in your theme or plugin

Just add this line before calling wp_delete_user function: require_once(ABSPATH.'wp-admin/includes/user.php'); wp_delete_user($user->ID);

Get activated theme on every site in WordPress Multisite using Python

This is a more precise way to get the list of activated theme on each blog in your WordPress Multisite:

Get activated theme on every site in WordPress Multisite using wp-cli

You can use this: 1. Install wp-cli . 2. Create a bash script (export_blog_theme.sh) with the following content #! /bin/bash for url in $(wp site list --field=url --path=/path/to/your/wordpress/root) do         theme=$(wp option get template --url="$url" --path=/path/to/your/wordpress/root)         echo "$url,$theme" done 3. Make script executable: $ sudo chmod +x export_blog_theme.sh 4. Run the script: $ sudo -u www-data ./export_blog_theme.sh > blog_theme_list.csv Notes: Sometimes, the script return no result because of caches or WordPress db connection limitation.

Change background image randomly from a directory using Ajax in WordPress

A couple weeks ago, I'm working on a project that required me to develop a WordPress theme. One of the things that interested me was to create a block (html, in the front page) that change its background image randomly every time I reload the page. Here is how I did that: The main idea here is using Ajax to dynamically change background of a div tag to a random image loaded from a folder inside the theme's root every time I reload the home page. 1. functions.php add_action('init', 'enqueue_scripts_styles_init'); function enqueue_scripts_styles_init () { wp_enqueue_script( 'ajax-script', get_template_directory_uri().' /js/myscript.js ', array('jquery')); wp_localize_script( 'ajax-script', 'ajax_object', array( 'ajaxurl' => admin_url( 'admin-ajax.php' ) ) ); } add_action('wp_ajax_get_rand_img', 'get_rand_img'); add_action('wp_ajax_nopriv_get_rand_img', 'get_rand_...

Generate static html file from WordPress page

OK, Is your WordPress page rarely get updated, let's say once a day or a week. If so, you can use the following technique to reduce the load (queries) to the database especially in multisite deployment: Write a script to generate static content with updates from the database only once a day or a week. Then your users will access this static page instead of the heavy loading WordPress page with hundreds of database queries. 1. Create a wordpress template file wp_template.php (place it in your template root, e.g. /var/www/wordpress/wp-content/themes/mythemes/) which will get data from the database. For example: 2. Create a crontab to run this command every day at 1AM to generate the static html file in the web root: /usr/local/bin/blog_static_gen.sh: #! /bin/bash $ cd /var/www/wordpress/wp-content/themes/mythemes $ php wp_template.php > /var/www/wordpress/wp_template.html crontab: 0 1 * * * /usr/local/bin/blog_static_gen.sh 3. Then you can access the static co...

Multilevel drop-down menu in WordPress with Bootstrap 3

To integrate Bootstrap 3 navigation menu to WordPress you can use the following walker class: https://github.com/twittem/wp-bootstrap-navwalker But, the problem is it only allows a single dropdown level to honer BootStrap 3's mobile first philosophy. Fortunately, the guy this blog post had done a little hack to bootstrap and the walker class above to support multilevel drop-down menu: Blog post: http://www.jeffmould.com/2014/01/09/responsive-multi-level-bootstrap-menu/ Github repo: https://github.com/jeffmould/multi-level-bootstrap-menu Basically, what you should do to have a bootstrap 3 style dropdown menu in your WordPress theme are: 1. Copy the  wp-bootstrap-navwalker.php file from the github repo to the theme's root directory 2. Add this style to your theme: .dropdown-submenu{position:relative;} .dropdown-submenu>.dropdown-menu{top:0;left:100%;-webkit-border-radius:0 6px 6px 6px;-moz-border-radius:0 6px 6px 6px;border-radius:0 6px 6px 6px;} .dropdo...

Add custom javascript to your WordPress theme without touching the template code

Image
Sometimes you want to add some custom effect to your WordPress template but don't want to make any changes to the theme code. Here you go, use this New Custom Javascript Editor plugin in your WordPress instance: Github repository: https://github.com/dangtrinh/Custom-Javascript-Editor 1. Install $ cd /path/to/your/wordpress/doc/root/wp-content/plugins $ git clone https://github.com/dangtrinh/Custom-Javascript-Editor 2. Activate the New Custom JavaScript Editor in your WordPress Admin Dashboard 3. Go to Appearance >> Custom JavaScript  or this url: http://yourdomain.com/wp-admin/themes.php?page=custom-javascript 4. Add your custom javascript and click Update

Deploy Redmine 2.6 with Unicorn, Supervisor, and NginX

This blog post is about how to deploy Redmine 2.6, the opensourced project management software in a Ubuntu server with unicorn, supervisor and nginx. A. Install Redmine: 1. Create a mariadb database for redmine: * database name: redmine * user: redmineuser * password: redminepasswd 2. Clone the redmine's git repo: $ git clone https://github.com/redmine/redmine.git $ cd redmine $ git checkout -b 2.6-stable 3. Configure database connection: Copy config/database.yml.example to config/database.yml and edit this file in order to configure your database settings for "production" environment. production:   adapter: mysql2   database: redmine   host: localhost   username: redmineuser   password: redminepasswd (for ruby 1.9) 4. Install dependencies: $ gem install bundler $ bundle install --without development test 5. Session store secret generation: $ rake generate_secret_token 6. Database schema objects creation: $...

How to fix RSS Feed parsing error in Wordpress

From last night, whenever I tried to access the feed url of my Wordpress blog, I saw this error: This page contains the following errors: error on line 12 at column 49: Entity 'ndash' not defined Below is a rendering of the page up to the first error. So, here is how I fixed it: 1. First, go to the online feed validator tool to see what was wrong: http://feedvalidator.org/ Enter my blog feed url and see the result. It turned out that there is something wrong with the feed title tag. It includes a strange character called – 2. Go to the template's include folder, open the template file which defines the feed's title and remove that character. I'm using genbu theme, so I will edit genbu/includes/tamatebako.php , the   tamatebako_wp_title function as following line: ...         /* Add Site Description */         if( is_front_page() ){                 if ( $site_description )...

django-suit - A beautiful admin interface

Image
If you are tired of the poor interface of the Django admin app, you can try django-suit . Django Suit Project's official website:  http://djangosuit.com/ 1. Install django-suit: (virtualenv)$ pip install django-suit 2. Add ' suit ' app to INSTALLED_APPS of your Django project, before the 'django.contrib.admin': INSTALLED_APPS = (          ' django.contrib.staticfiles ', ...         ' suit ',         'django.contrib.admin', ... )  Notes: you also need to include the django.contrib.statifiles app 3. Make sure you include this following template context processor: TEMPLATE_CONTEXT_PROCESSORS = ( ...         " django.core.context_processors.request ", ) 4. Collect static data for your Django project (in production server with DEBUG=False ): (virtualenv)$ ./manage.py collectstatic 5. Refresh the admin page in your browser and enjoy the beauty: Reference...