Programming, WordPress

WPML custom post type slug translation

If you are struggling to translate the slugs for custom post type then, read this article and try to implement the solution in your website.

Suppose, we have custom post type ‘programs‘ and we want to update its slug for each available languages.

I would like to recommend the following steps for translating the custom post type slugs in different languages :

  1. Go to WPML -> String Translation
  2. From the String Translation admin screen search for the English slug “programs”, select the available strings and delete it. Similarly, from the String Translation admin screen search for the slug “programas” and delete it. In short, delete any string translation for related custom slugs.
  3. Go to WPML-> Translation Management-> Multilingual Content Setup and in the Custom posts slug translation options, check the box to “Translate custom posts slugs (via WPML String Translation).” and click Save.
  4. Then, scroll down to custom post types, where you can see the lists for posts ready to to be translated. Select the post to be translated and Save it. Once the page refreshes, you can see the original posts slug  and fields where you can enter the slugs for each of your secondary languages. Save the translated custom post slugs.
  5. Check the posts links for each language.Finally, you can see the fine links with the translated slug for each language.

Hits: 28

Standard
Programming

Language specific post count

If you are using WPML and you want  to  count current language posts, you can use the following code :

Don’t Forget to add  ‘suppress_filters’ => false parameter  in your query.

If you want to display total posts count, irrespective of the languages; then  use  ‘suppress_filters’ =>true parameter in your  query.

Hits: 10

Standard
Programming

Set your own cache clean url

Do you want to give subscriber privilege  to delete the cache created by supercache plugin or any other plugins ? if you say “Yes” , follow this article .

    1. Create your template file.
    2.  Create a function that recursively delete the files and folders ,  in your functions.php file
    3.  Provide your cache folder directory in the template file you created. My cache folder is inside the wp-content folder. Call the function in the same template file.
    4. Create a new page in your dashboard and and load the template file,  just created.
    5. Access the page url,  cache of the site site is cleard with the ‘Cache has been cleaned’ message . i.e. http://your-site.com/delete-cache
    6. Check your cache folder, you don’t see any files. All the files are removed from the cache folder

This  is very useful, when user other than admin wants  privilege  to delete the cache of the website.

Hits: 12

Standard
Programming

Character limit message to text & textarea fields in ACF

Sometimes, you might one to limit the character of text that user input in the text or textarea field to prevent user input from breaking the design of the website. This feature is included in the ACF plugin, but it doesn’t display any info when the character limit is reached.

Lets follow the following steps to display the message for maxlength in input fields

1. Load your js document in the admin page. I want to load my js file only for Alert Options Page.

2. The following js code displays the character left in the input field when the user input the text in textarea field. Add this js code in your character-limit.js file and save the file.

Now, you can see the character limit message when you add the content in your ACF textarea field.

Hits: 860

Standard
Programming

Automatically open external links in new tab

Do you want to open all the external links of your website in a new tab ? If you say ‘YES“, just copy the  following code and paste it in your function.php file.

 

The aforementioned script excludes, if teljavascript.void(0), hash(#), mailto and site_url() are in the href of the anchor tag.

Hits: 7

Standard