0

I downloaded an HTML template and did the necessary conversions to create a wordpress theme. The location of the template files is in /wp-content/themes. When I look at my template and I go to my website, the URL is simple www.mysite.com. However, initially when I clicked on any of the links, the URL was www.mysite.com/wp-content/themes/Template/mypage.html instead of the desired www.mysite.com/mypage.html. I using an FTP to put all of my template files in my root directory, however, in order to make changes to my theme it wants me to edit the header.php file that is in my /wp-content/themes folder.

Is there a way to delete the wp-content folder completely, and have wordpress look for your theme in your root directory? Or is this bad practice?

3
  • You'll be better off changing the links to include the forward slash character (/) in front of them, that way, the links are always gonna point to the root of your domain. E.g. <a href="/mypage.html">Link</a>. Commented Jun 28, 2017 at 13:20
  • @edmundo okay, I did that and it works for my pages, but right now I'm editing links in the header section and it wont recognizes changes made to header.php in the root directory - only ones made to the header.php in wp-content/themes. Is there a way to either change the reference to the header file to be in the root directory? Or is there a way where I won't have to edit the header file at all? I was told to put my html for my nav bar in the header.php file Commented Jun 28, 2017 at 13:27
  • You should not be linking to theme files directly. You create pages and posts in admin interface which get rendered by WP with the appropriate theme template. You use template tags in your theme to output your content, including links to other pages / posts, etc..
    – Milo
    Commented Jun 28, 2017 at 17:06

1 Answer 1

1

It is definitely bad practice to try to move themes (or uploads or plugins) outside of the wp-content folder. WP's structure ensures that WP can find all the necessary resources. Anytime you move things outside of its structure, odd quirks and broken bits tend to appear. So, stick with /wp-content/themes/your-theme-slug/ and make things more dynamic.

I would suggest that instead of hard-coding the links, you use wp_nav_menu() instead. You'll set up a custom menu in your theme one time. From then on, you edit the links within the menu inside wp-admin - you can either use the Customizer or the Appearance > Menus page.

functions.php file in theme:

<?php // add theme support for menus
add_action('after_setup_theme', 'wpse_add_menu_support');
function wpse_add_menu_support() {
    add_theme_support('menus');
}
// add a particular menu
add_action('init', 'wpse_nav_menu');
function wpse_nav_menu() {
    register_nav_menu('topnav', 'Main navigation of the website');
} ?>

header.php file in theme:

<?php // display the menu
wp_nav_menu(array('theme_location' => 'topnav', 'container' => ''));
?>

Then manage the links in a WYSIWYG way. Another benefit of doing things this way instead of hard-coding is if you ever change the permalinks of any of your pages, WP will automatically update your navigation, because it saves the ID of the post rather than the slug/permalink.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.