Welcome to ManageWP.org

Register to share, discuss and vote for the best WordPress stories every day, find new ideas and inspiration for your business and network with other members of the WordPress community. Join the #1 WordPress news community!

×

Development | codelink.pro | Jun. 11, 2018

Should you combine or enqueue Javascript project files?

Discusses whether it's better to enqueue Javascript files one by one, or combine into one with a build tool.

Should you combine or enqueue Javascript project files?

Development | codelink.pro | Jun. 11, 2018

In a previous post we covered what the best way was to include jQuery in WordPress. In this post, I’m going to talk a little more about the best ways to include Javascipt files.
When your doing a lot with Javascript, you can end up with a few scripts/libraries supporting your custom script. You might also have several custom scripts to include, but what’s the best way of including these? Would you enqueue each of them seperately? Would you combine the custom ones but enqueue the third party ones? Or would you combine everything you are using in your project into one script and enqueue that?
I’m going to discuss my approach and why I think it’s best.
So, what you might do is to enqueue each supporting scrip then list your custom script, like so:
wp_enqueue_script( 'select2', trailingslashit( get_template_directory_uri() ) . 'select2.js', array( 'jquery' ) );
wp_enqueue_script( 'custom, trailingslashit( get_template_directory_uri() ) . custom.js', array( 'jquery', 'select2') );
It’s important in this scenario that you list the dependant scripts as dependencies, rather then just list them in order. This is to make sure that they are loaded prior to the one

Community | codelink.pro | May. 8, 2018

Best practices for adding jQuery or Javascript to Wordpress

How to add a custom jQuery script without breaking other page functionality.

Best practices for adding jQuery or Javascript to Wordpress

Community | codelink.pro | May. 8, 2018

How to make sure your jQuery code is compatible with WordPress, theme’s and other plugins. WordPress installations these days are loaded with many plugins. To make sure that your custom plugin, that contains jQuery/Javascript, does not break other plugins it is important to wrap your code in their own private containers.
Page functionality can break when two differen’t libraries from two different plugins conflict with each other.
In JavaScript there is the container called a IIFE. Think of a IIFE as a CLASS(blueprint) in another programming language like PHP.
Immediately Invoke Function Expression.
What it does is, is to wrap code in it own container so that any variable names or methods stay unique inside that container and can’t be picked up or use by other jQuery/JavaScript on the current WordPress installation. Think of it as a isolated container that contains code to not be shared or used by other jQuery/JavaScript libraries or code.
For example of how you would wrap your jQuery/JavaScript in a IIFE
12345678910111213141516
(function($){window.ready(function{// code});document.ready(function{// code});// Code goes in here.// Please take note that I am passing

Tutorials | codelink.pro | May. 22, 2018

Running WordPress locally on Linux or mac with WP CLI

How to run WordPress using the WP CLI, without MAMP. Running with the WP CLI is a very quick and convenient way of running WordPress that doesn't require a MAMP / LAMP stack.

Running WordPress locally on Linux or mac with WP CLI

Tutorials | codelink.pro | May. 22, 2018

There are a multitude of ways to run WordPress locally. One of my favorite and simplest ways is to use WP CLI. The WP CLI provides command line tools for WordPress. In a previous article, I covered how to run WordPress using just PHP and MySQL, no Apache or Nginx. In this article I’m going to cover how to do the same but with WP CLI.
With this method, you don’t need to install anything like MAMP, XAMPP and skip can skip the complexity of running Docker or Vagrant when you don’t need them. You don’t even need Apache or Nginx. It’s a super quick and easy way to run WordPress on Linux or mac and all you need is PHP, MySQL and the WP CLI.
Using the WP CLI adds a level of abstraction and allows you to not only download, setup and serve WordPress but also do the config and install.
If you want to go deeper and learn more about using the WordPress command line, check out our eBook
Install PHP & MySQL
This is going to be different for different systems so probably best that you look that up. You’ll need to know your MySQL for a later stage, so make a note of that.
To check what you already have installed:
Here is my personal cheatsheet for installing

Tutorials | codelink.pro | Mar. 13, 2018

Speed up WP_Query requests to only return what is needed from the database

How to modify wp_query to only return the data you need from the database. This can speed up your site when the database get's larger.

Speed up WP_Query requests to only return what is needed from the database

Tutorials | codelink.pro | Mar. 13, 2018

Here is a nice tip when you would like to speed up your database query for a given page. When you make a query for certain specific data in WordPress, WordPress by default will return ALL the data in an object. 95% of the time it is not required to return all the data from the database. It will just make your page loading slow especially if you have a WordPress Database that has taken on some fat. What you want WordPress to do is to STOP when it found the number of sufficient data/rows and not run around like a headless chicken on a black Friday sale collecting everything it possibly can. Inside the WP_Query CLASS, class-wp-query.php(line 684) there exist a argument to assit with this:
@type bool $no_found_rows Whether to skip counting the total rows found. Enabling can improve performance. Default false.
Extraction from the code inside the class-wp-query.php where it test to see if the option was set when the query was passed.:
123456789
Line: 1806// If true, forcibly turns off SQL_CALC_FOUND_ROWS even when limits are present.if ( isset($q['no_found_rows']) )$q['no_found_rows'] = (bool) $q['no_found_rows'];else$q['no_found_rows'] = false;public function parse_query( $query = '' ) ...

Plugins | codelink.pro | Mar. 6, 2018

Markdown for WordPress

I missed using Markdown, so I explored what options were available for using Markdown in WordPress posts. In this article I evaluate the options I found for using Markdown with WordPress.

Markdown for WordPress

Plugins | codelink.pro | Mar. 6, 2018

Something I really like about developing with other languages / frameworks is that many of them have servers built in. This is very convenient, so it was frustrating not having this with WordPress. Over the years I have run WordPress in many different ways, MAMP, MAMP Pro, LAMP, XAMPP, Flywheel, Vagrant, Docker etc. But all methods I’ve used have had issues where I have had to spend a lot of times troubleshooting it. The built in servers that Ruby, Jekyll etc have make local dev simple and quick. You can get on with the actual coding and not focus to much on the server stuff.
But PHP does have a inbuilt PHP server, since 5.4.0, it just doesn’t get mentioned very much. It’s actually a great way of running a local install of WordPress when you don’t need bells and whistles, when all you need is a basic WordPress install.
You’ll need PHP and MySQL
All you need is PHP installed and a MySQL server running, which I won’t cover in this tutorial, since it’s is platform specific. So from here on, I’m going to assume from here that you have them installed. Google it and come back when your setup.
To check what you already have installed, type or

Tutorials | codelink.pro | Mar. 11, 2018

How to add shortcodes dynamically to a WordPress Post or Page

How to dynamically add shortcodes to multiple pages. This saves having to add shortcodes to potentially thousands of pages manually.

How to add shortcodes dynamically to a WordPress Post or Page

Tutorials | codelink.pro | Mar. 11, 2018

Here is a code example of how to add shortcodes dynamically to a WordPress Post or Page. Why do you want to do this? It happened that I had a request from a client to only show an introduction part of the description section and hide the rest with a “read more” feature. I found this plugin called “WP show more” on the WordPress repository that is able to hide certain parts of content if the content is wrapped inside the plugin’s shortcodes.
For example, to hide the second paragraph to conserve space you need to add the shortcodes before and after the second paragraph.:
Pellentesque elementum interdum nibh blandit scelerisque. Praesent in nibh eu odio finibus ultricies. Sed sit amet placerat justo. Quisque nec diam ultrices, molestie felis ac, convallis augue. Pellentesque euismod mauris at leo feugiat interdum. Praesent tempor lorem eget erat vulputate varius. Aliquam eget cursus nulla. Suspendisse potenti. Integer placerat augue magna, ac pellentesque ante finibus non. Sed vitae eros convallis, imperdiet massa ultrices, placerat nisi.
[show_more]
Vivamus orci erat, dictum vitae ultrices at, interdum tempus ex. Proin varius sodales vestibulum. Etiam pulvinar