Community Forums › Forums › Archived Forums › Design Tips and Tricks › Sub-header anchor links
- This topic has 6 replies, 2 voices, and was last updated 8 years, 7 months ago by
Christoph.
-
AuthorPosts
-
June 28, 2016 at 9:39 am #188452
manavecplan
MemberHey,
If you look at the H2 headers on this page(http://conversionxl.com/this-i-believe/) you'll see a link icon appear at the right of the header when you over over it.
If you look at the page source, there's no ID assigned to any of the headers so basically the IDs are being generated on the fly using what I believe is the Anchor.js library(http://bryanbraun.github.io/anchorjs/)
So, what I've done to load the library is paste this into the Genesis Theme Settings:(<script src="https://cdnjs.cloudflare.com/ajax/libs/anchor-js/3.2.0/anchor.js"></script>)
Naturally, it doesn't load. 🙁
I've also tried loading it locally via:
function add_anchors() { wp_enqueue_script( 'anchor_script', get_template_directory_uri() . '/js/anchor.js', array ( 'jquery' ), 1.1, true); wp_enqueue_script('anchor_script'); } } add_action( 'wp_enqueue_scripts', 'add_anchors' );
Again, no go.
What am I doing wrong here?
June 28, 2016 at 10:13 am #188455Christoph
MemberHi,
try
get_stylesheet_diretory_uri()
or, if you want to use the CDN, you can use
wp_enqueue_script( 'anchorjs', '//cdnjs.cloudflare.com/ajax/libs/anchor-js/3.2.0/anchor.js', array( ), CHILD_THEME_VERSION );
June 28, 2016 at 11:47 am #188459manavecplan
MemberNo go... 🙁
Current code looks like this but neither function fires:
function add_anchors() { wp_enqueue_script( 'anchor_script', get_template_directory_uri() . '/js/anchor.js', array ( 'jquery' ), 1.1, true); wp_enqueue_script('anchor_script'); } add_action( 'wp_enqueue_scripts', 'add_anchors' ); function adda_anchors() { wp_enqueue_script( 'anchora_script', get_stylesheet_directory_uri() . '/js/anchor.js', array ( 'jquery' ), 1.1, true); wp_enqueue_script('anchora_script'); } add_action( 'wp_enqueue_scripts', 'adda_anchors' );
Also, to be clear, the js file is inside the js folder inside the Genesis Child Theme folder
June 28, 2016 at 11:56 am #188460Christoph
MemberI just used the existing "enqueue function" in the child theme.
wp_enqueue_script('anchora_script');
should not be necessary.
Do you get an error message in the Google Console?
June 29, 2016 at 1:00 pm #188593manavecplan
MemberThat question provided a great bit of learning Christoph! 😀
So, I checked the console and the network both...
When I check the console, it gave me the following error: Uncaught SyntaxError: Unexpected token < anchor.js?ver=1.1:5
When I tab over too Network, it tells me that this is a 304 Not Modified error; which apparently isn't an error at all.
So, so close...
function add_anchors() { wp_enqueue_script( 'anchora_script', get_stylesheet_directory_uri() . '/js/anchor.js', array ( 'jquery' ), 1.1, true); } add_action( 'wp_enqueue_scripts', 'add_anchors' );
July 6, 2016 at 10:24 am #188962manavecplan
Member*bump*
July 6, 2016 at 10:20 pm #188994Christoph
MemberIt means you have a syntax error somewhere that is stopping jQuery from parsing the code.
You are missing single quotes around the
1.1
"version number" in the wp_enqueue_script
(I would use CHILD_THEME_VERSION anyway.)
-
AuthorPosts
- The forum ‘Design Tips and Tricks’ is closed to new topics and replies.