0

just started converting a site into wordpress when I ran into an issue. I am stripping the default output Table down to just the A tags, but sadly wordpress does not put any of the styling information on the A tags (class or id)

$menuArgs = array(
     //...Args...
);
echo strip_tags(
    wp_nav_menu( $menuParameters ), '<a>' );?>

Is there any way to add class="MenuLink" to every Echoed A tag easily?? or will I have to use some substr_replace like function ~

4
  • If i understood well, i think the easier way is to use a "replace all" in a text editor. in order to add a class to all <a> in your page Commented Dec 29, 2013 at 20:31
  • so something like echo str_replace ( '<a>' , '<a class="HeaderNavigation-Button">' , Subject ); Commented Dec 29, 2013 at 20:33
  • If you have a class on every single a element in another element, the CSS should just target parent a. Commented Dec 29, 2013 at 21:22
  • I was thinking about that... Sadly this is a "wordpress theme" and the clients are not coders... So I was hoping to avoid neededing to change that if they wanted to add more links later Commented Dec 29, 2013 at 21:41

2 Answers 2

2

I think it is better to use a custom walker to add that class. Look Cleaner output for wp_nav_menu() and Improve your Wordpress Navigation Menu Output and T5_Nav_Menu_Walker_Simple — Gist

Sign up to request clarification or add additional context in comments.

Comments

1

I ended up settling for this instead of Cleaner output just due to lower overall code~

           <?php 
                $menuParameters = array(
                    'theme_location' => 'Header Menu (Part1)',
                    'container'       => false,
                    'echo'            => false,
                    'items_wrap'      => '%3$s',
                    'depth'           => 0,
                ); 

            echo str_replace (
                '<a' , '<a class="HeaderNavigation-Button" ' , 
                strip_tags(
                    wp_nav_menu( $menuParameters ),
                '<a>' ) ); 
            ?>

If anyone has a cleaner way, please let me know

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.