How to add code to all WordPress pages

by seoed
5 replies
Hello,

I wanted to add a code which should be applied to all pages
I have on WP. How can I do this?

Regards
#add #code #pages #wordpress
  • Profile picture of the author kiopa
    Banned
    Go into the /wp-content/themes/ directory, and find the current theme you're using. Inside that directory, there will be a header.php file. Just open that file up in your text editor, and add whatever code you need. It'll be added to every page of your site then.

    Hope that helps!
    {{ DiscussionBoard.errors[2356490].message }}
  • Profile picture of the author Rob Thayer
    If you're trying to use something like Google Analytics, I usually put it in the Footer code. In your WP Dashboard, along the left, click on Appearance and then Editor. On the right side of the page, you'll see the various code modules... click on Footer. Put your code somewhere before the </body> tag. You can also put it at the end of the Main Index Template code.

    Caveat: If you don't know what you're doing, get someone to help you. Also, if you're using a theme that has an encoded Footer section (so you don't jerk around with the links they put in there), it can screw up your blog so make sure you have the original footer.php file ready to transfer back over to your host.
    {{ DiscussionBoard.errors[2356495].message }}
  • Profile picture of the author cashcow
    ... Or if you wanted something on each post, like before the actual text of the post or after it, then you might want to edit the index.php file (or depending on your theme whatever the main file for posts is)

    Lee
    Signature
    Gone Fishing
    {{ DiscussionBoard.errors[2356503].message }}
  • Profile picture of the author seoed
    thank you all for your fast responses!
    Signature
    {{ DiscussionBoard.errors[2356581].message }}
  • Profile picture of the author ElectricChili
    I've learned that when modifying core WP files, you should always make a copy of the original file. I d/l the file I want to tweak and then change the extension of the file name on the server from .php to .bak.

    Another tip is to be careful of using Notepad as it doesn't always parse the linebreaks correctly and can jack up the code. I use Notepad ++ which is a nice freeby. It uses tabs which is nice when you're working on multiple files and has syntax highlighting to help you find your way around the code.

    Rich
    {{ DiscussionBoard.errors[2356628].message }}

Trending Topics