Categories
Wordpress

How to set up your .htaccess to allow only certain subdirectories

Until I update and reorganize my old projects, all of them are not available for the moment.

Thing is, most of my projects are, like this blog, subdomains of avanzartewebs.com.

So, how could I allow you to read my blog but not reaching for now the other projects?

Well, all my projects are under an Apache webserver  (another popular option is ngix , but my povider uses Apache), so I can use an Apache configuration file named .htaccess 

On my webserver, all my projects are just subdirectories of the public_html folder, which is the one that stores the things that will be public.

public_html has its own .htaccess but each project could have its own as well. Rules would be overrided depending on the case.

I found what I should do in stack overflow

https://stackoverflow.com/questions/7649794/htaccess-deny-root-allow-specific-subfolder-possible

The user nachito tells us what to do. I hope it helps:

.htaccess directives apply to that directory, and all subdirectories thereof, so you should disallow access in your DocumentRoot,

http://sub.mydomain.com/.htaccess:

Order deny,allow
Deny from all

And override that in any specific subdirectories you would like to allow access to,

http://sub.mydomain.com/test/.htaccess:

Order allow,deny

Allow from all
Categories
Wordpress

How to be able to add “target” HTML attribute on WordPress profile edit page

One of the first things i liked when starting this new blog based on wordpress, is that, when I was writing my bio, I could use HTML tags on the textarea! (in case you didn´t know it)

profile-section-tags

But joy turned into “sorrow” when I noticed I couldn´t use the HTML target=”_blank” attribute. It will be simply removed if you try to add it.

target=”_blank” makes possible that when you click on the link, page is opened on a new tab.

I investigated a bit and I found a solution here,

https://wordpress.org/support/topic/links-on-biographical-info-not-opened-in-new-tab/

bcworkz tells us it has been made that way for a good reason and it is a poor practice:

According to many UI experts, causing links to open in new windows is not advised. It confuses some users, and users who like links opened in new windows will do so for themselves anyway. It’s poor practice to presume you know what users want to do. WP devs intentionally disallowed the target attribute for this very reason. You may wish to rethink this strategy.

Despite that, I find much more comfortable that the link is opened on a new tab, and the same user kindly gives us the code to do it.

 // Allow target attr in anchor tags

    function bcw_allow_target( $attr, $context ) {

        if ('pre_user_description'== $context ) $attr['a']['target'] = true;

        //"rel" attr allowed by default in this context

        return $attr;

    }

    add_filter('wp_kses_allowed_html', 'bcw_allow_target', 10, 2 );

You must add it on the functions.php file of your wordpress theme. BUT I STRONGLY ENCOURAGE YOU TO CREATE A CHILD THEME FIRST.

Why and how to do that will be a post soon. For the moment take a look here.

What he does is adding a filter. Actions and filters are called in WordPress HOOKS, and are very important on this platform.

As said on this spanish blog, what filter do more or less is to modify the info output before it is recorded on the database or shown on the screen.

For example, one typical filter is called the_content (see available filter list here).

the_content for example can be used to concatenate a text to a given content which will be passed as parameter

<?php

/*first you declare what filter must do on a function
function add_text_to_content($content) {
    $content .= " | written by Pablo López";

    return $content;
}

/*then you use add_filter() in order to be able to use the filter
add_filter( 'the_content', 'add_text_to_content' );

So, with the filter given by bcworkz we are able to append the target HTML attribute to our html code when we are editing our profile page (check it if you want)

 

 

Categories
Wordpress

How to install Classic Editor on wordpress

editor-clasico-wordpress

 

This is one of the first things I felt I had to change when this site was installed.

I don´t know if you, as wordpress user, are used to the new editor like the block default editor, or the gutenberg one. But I think if something works, then don´t change; that´s why I installed the Classic Editor Plugin.

Works like a charm. Now, I am ready to post!

In case you want to know more about WP Plugins and how to intsall them, check this link